PAT_A1005
PAT甲级1005.
目录
A1005
题目
样例
输入:
12345
输出:
one five
思路和坑点
由于题目的数字不超过100位,因此每位的和最大不会超过900,因此对和分三段进行判定输出。(英文单词不要拼错)
AC代码
#include<bits/stdc++.h>
using namespace std;
int main(void){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt","r",stdin);
#endif
string shu[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string str;
int ans=0;
cin>>str;
for(int i=0;i<str.size();i++){
ans+=str[i]-'0';
}
if(ans>=100)
cout<<shu[ans/100]<<' '<<shu[ans/10%10]<<' '<<shu[ans%10];
else if(ans>=10)
cout<<shu[ans/10]<<' '<<shu[ans%10];
else
cout<<shu[ans];
return 0;
}