- Spell It Right (20)
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 (<= 10100).
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:
12345
Sample Output:
one five
#include <bits/stdc++.h>
using namespace std;
int main()
{
char ma[12345];
long long int sum = 0;
scanf("%s", ma);
if(ma[0]=='0')
cout<<"zero"<<endl;
else{
for(int i=0; ma[i]; i++)
{
sum = sum + ma[i] - '0';
}
int k[12345];
int top = -1;
while(sum)
{
int a = sum % 10;
k[++top] = a;
sum /= 10;
}
int flag = 1;
for(int i=top; i>=0; i--)
{
if(flag!=1)
{
printf(" ");
}
else
{
flag = 0;
}
if(k[i]==1)printf("one");
else if(k[i]==2)printf("two");
else if(k[i]==3)printf("three");
else if(k[i]==4)printf("four");
else if(k[i]==5)printf("five");
else if(k[i]==6)printf("six");
else if(k[i]==7)printf("seven");
else if(k[i]==8)printf("eight");
else if(k[i]==9)printf("nine");
else if(k[i]==0)printf("zero");
}
cout<<endl;
}
return 0;
}
本文介绍了一个程序设计问题:给定一个非负整数N,计算其所有位数的和,并将每位数字用英文单词表示。输入为一个不超过10^100的大整数,输出为该整数各位数字之和的英文单词形式。
8408

被折叠的 条评论
为什么被折叠?



