1005 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
翻译:
1005 正确拼写 (20 分)
给定一个非负整数N,您的任务是计算N,然后以英文输出总和的每个数字。
输入规格:
每个输入文件包含一个测试用例。每个案例占用一行,其中包含N (≤10100).
输出规格:
对于每个测试用例,在一行中输出英文单词中和号的数字。两个连续单词之间必须有一个空格,但行尾不能有额外的空格。
示例输入:
12345
示例输出
one five
#include<iostream>
using namespace std;
int main()
{
string a;
cin>>a;
int sum=0;
int len;
for(int i=0;i<a.length();i++)
{
int b;
b=a[i]-'0';
sum=sum+b;
}
string c=to_string(sum);
len=c.length();
for(int i=0;i<len-1;i++)
{
switch(c[i]-'0')
{
case 1:{cout<<"one ";break;}
case 2:{cout<<"two ";break;}
case 3:{cout<<"three ";break;}
case 4:{cout<<"four ";break;}
case 5:{cout<<"five ";break;}
case 6:{cout<<"six ";break;}
case 7:{cout<<"seven ";break;}
case 8:{cout<<"eight ";break;}
case 9:{cout<<"nine ";break;}
case 0:{cout<<"zero ";break;}
}
}
switch(c[len-1]-'0')
{
case 1:{cout<<"one";break;}
case 2:{cout<<"two";break;}
case 3:{cout<<"three";break;}
case 4:{cout<<"four";break;}
case 5:{cout<<"five";break;}
case 6:{cout<<"six";break;}
case 7:{cout<<"seven";break;}
case 8:{cout<<"eight";break;}
case 9:{cout<<"nine";break;}
case 0:{cout<<"zero";break;}
}
cout<<endl;
}