标签:title english pre car ever lse using list NPU
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.
Each input file contains one test case. Each case occupies one line which contains an N (≤10?100??).
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.
12345
one five
注意:题中有一个case是0
1 #include<iostream> 2 #include<string> 3 #include<stack> 4 5 using namespace std; 6 7 string numEnglish[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; 8 9 int main() 10 { 11 string str; 12 int sum = 0; 13 stack<int> s; 14 15 getline(cin,str); 16 17 for(int i=0;i<str.size();++i) 18 sum += str[i]-48; 19 20 if(sum == 0) 21 cout<<"zero"<<endl; 22 else 23 { 24 while(sum) 25 { 26 s.push(sum%10); 27 sum /= 10; 28 } 29 30 cout<<numEnglish[s.top()]; 31 s.pop(); 32 33 while(!s.empty()) 34 { 35 cout << " " << numEnglish[s.top()]; 36 s.pop(); 37 } 38 } 39 40 return 0; 41 }
PAT 甲级 1005 Spell It Right (20 分)
标签:title english pre car ever lse using list NPU
原文地址:https://www.cnblogs.com/cdp1591652208/p/10227486.html