水题,和中文没啥区别不说了。
#include<cstdio> #include<cstdlib> #include<iostream> #include<algorithm> using namespace std; char maps[10][10]={ {"zero"},{"one"},{"two"},{"three"},{"four"},{"five"},{"six"},{"seven"},{"eight"},{"nine"} }; int main() { char ch; int sum=0; while ((ch = getchar()) != ' ') { sum += (ch -'0'); } int a[1000],i=0; while (sum > 10) { a[i] = sum%10; sum /= 10; i++; } a[i] = sum; while (i>0) { cout<<maps[a[i]]<<" "; i--; } cout<<maps[a[0]]<<endl; return 0; }