题目重述:
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
题目翻译:
给出一个非负整数N,你的任务是计算该整数的各个数位之和
输入:包含一行,N(<10的100次方)
输出:和的各个位数的英文
思路:终于遇到了能思考出来的题目了,啊(*^▽^*),首先从键盘获取N,没输入一个便加到sum上,最后计算出sum的值即为N各个位数之和。将sum的各个位数保存到一个数组NTE[]中,编写函数数字转英文,然后逆序处理并输出NTE[]
参考代码:
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
string ToEnglish(int x){
string str;
switch(x){
case 0:str="zero";break;
case 1:str="one";break;
case 2:str="two";break;
case 3:str="three";break;
case 4:str="four";break;
case 5:str="five";break;
case 6:str="six";break;
case 7:str="seven";break;
case 8:str="eight";break;
case 9:str="nine";break;
}
return str;
}
int main(){
char x;
int sum=0;
int NTE[101],j=0,Count = 0;
do{
x=cin.get();
if(x!='\n')
sum+=x-'0';
}while(x!='\n');
//cout<<sum;
if(sum==0){
cout<<"zero";
}else{
int n = sum;
while(n!=0){
int g = n%10;
NTE[j++] = g;
Count++;
n/=10;
}
for(int i=Count-1;i>=0;i--){
string ss=ToEnglish(NTE[i]);
if(i==Count-1){
cout<<ss;
}
else{
cout<<" "<<ss;
}
}
}
}