PAT (Advanced Level) 1005. Spell It Right (20)
简单题。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<vector> using namespace std; const int maxn=100+10; char s[maxn]; int tmp[maxn],tot; char ans[15][7]={ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; int main() { scanf("%s",s); int num=0; for(int i=0;s[i];i++) num=num+s[i]-'0'; if(num==0) { printf("zero\n"); } else{ tot=0; while(num) tmp[tot++]=num%10,num=num/10; for(int i=tot-1;i>=0;i--) { printf("%s",ans[tmp[i]]); if(i>0) printf(" "); else printf("\n"); } } return 0; }