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:12345Sample Output:one five// 題目分析:字符串數組存儲字符串常量// 代碼#include <iostream>#include <string>#include <vector>using namespace std;int main(){ char a[110]; string strs[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; scanf("%s",a); int i=0; int sum=0; while(a[i]!='/0'){ sum+=a[i]-'0'; i++; } vector<int> v; while(sum!=0){ v.push_back(sum%10); sum/=10; } for(int i=v.size()-1;i>0;i--){ cout<<strs[v[i]]<<' '; } if(v.empty()){ cout<<"zero"; }else{ cout<<strs[v[0]]; } system("pause"); return 0;}//結果
新聞熱點
疑難解答