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
此题目还是比较简单的。注意to_string ,-‘0’等的运用,将有限个直接转换存在数组里更为方便,1—>one。。。
#include <iostream>
#include <string>
using namespace std;
void e(int c) {
switch(c) {
case 0: cout << "zero"; break;
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;
}
}
int main() {
string s;
int sum = 0;
cin >> s;
for (int i = 0; i < s.length(); i++)
{
sum += s[i] - '0';
}
string sa = to_string(sum);
e(sa[0] - '0');
for (int i = 1; i < sa.length();i++) {
cout << " ";
e(sa[i] - '0');
}
system("pause");
}