您的位置:首页 > 其它

PAT甲级字符串处理1005 Spell It Right

2019-01-23 15:51 232 查看

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (≤10​100​​).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:

[code]12345

Sample Output:

[code]one five
[code]#include<bits/stdc++.h>
#include<math.h>
using namespace std;
char num[10][10]= {"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{
char s[110];
int sum[5],c=0,i;
scanf("%s",s);
for(i=0; s[i]!='\0'; i++)
c += s[i]-'0';
if(c==0)sum[0]=0;
else
{
for(i=0; c>0; i++)
{
sum[i] = c%10;
c /= 10;
}
for(i=i-1; i>0; i--)
printf("%s ",num[sum[i]]);
}
printf("%s",num[sum[0]]);
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: