【PAT甲级】1005 Spell It Right (20 分)
题意:
给出一个非零整数N(<=10^100),计算每位之和并用英文输出。
AAAAAccepted code:
1 #include<bits/stdc++.h> 2 using namespace std; 3 string s; 4 char num[17][17]={"zero","one","two","three","four","five","six","seven","eight","nine"}; 5 int main(){ 6 cin>>s; 7 int ans=0; 8 for(int i=0;i<s.length();++i) 9 ans+=s[i]-'0'; 10 int x=ans/100; 11 ans%=100; 12 int y=ans/10; 13 ans%=10; 14 int z=ans; 15 if(x) 16 cout<<num[x]<<" "<<num[y]<<" "<<num[z]; 17 else if(y) 18 cout<<num[y]<<" "<<num[z]; 19 else 20 cout<<num[z]; 21 return 0; 22 }
保持热爱 不懈努力
不试试看怎么知道会失败呢(划掉)
世上无难事 只要肯放弃(划掉)