题解
这题比较简单,字符串输入,然后每一项求和,求和结果一定在1000以内就分别讨论然后switch case输出对应英文字母就可以了
AC代码
#include <iostream>
#include <cstdio>
using namespace std;
void print(int a);
int main()
{
string s;
int cnt=0;
cin >> s;
for (int i=0; i<s.length(); i++)
cnt += int(s[i]-'0');
if(cnt<10)
print(cnt);
else if (cnt<100)
{
print(cnt/10);
printf(" ");
print(cnt%10);
}
else
{
print(cnt/100);
printf(" ");
print((cnt%100)/10);
printf(" ");
print(cnt%10);
}
return 0;
}
void print(int a)
{
switch(a)
{
case 0: printf("zero");break;
case 1: printf("one");break;
case 2: printf("two");break;
case 3: printf("three");break;
case 4: printf("four");break;
case 5: printf("five");break;
case 6: printf("six");break;
case 7: printf("seven");break;
case 8: printf("eight");break;
case 9: printf("nine");break;
default: break;
}
}
end