# 1005. Spell It Right (20)

400 ms

65536 kB

16000 B

Standard

CHEN, Yue

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. Spell It Right (20)
string ChangTostr(int n)//将数字对应到字符串
{
switch (n)
{
case 0:return "zero"; break;
case 1:return "one"; break;
case 2:return "two"; break;
case 3:return "three"; break;
case 4:return "four"; break;
case 5:return "five"; break;
case 6:return "six"; break;
case 7:return "seven"; break;
case 8:return "eight"; break;
case 9:return "nine"; break;
}
}

int main()
{
string s;
cin >> s;
int sum = 0;
for (int i = 0; i < s.length(); i++)
{
int num = s[i] - '0';
sum += num;//计算和
}
stringstream ss;
ss << sum;
string str = ss.str();//将整型转为字符串，方便理解
for (int i = 0; i < str.length(); i++)
{
int num = str[i] - '0';
if (i)
{
cout << " " << ChangTostr(num);
}
else
{
cout << ChangTostr(num);
}
}
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：1005. Spell It Right (20) 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)