1005 Spell It Right (20 分)
思路
非常大串的数字,利用string类型完美解决~
代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin>>str;
int len = str.length();
int a[10] ={0};
string strs[10]={"zero","one","two","three","four","five","six","seven","eight","nine"} ;
for(int i =0;i<len;i++)
{
if(int(str[i])==48)
a[0]+=1;
else if(int(str[i])==49)
a[1]+=1;
else if(int(str[i])==50)
a[2]+=1;
else if(int(str[i])==51)
a[3]+=1;
else if(int(str[i])==52)
a[4]+=1;
else if(int(str[i])==53)
a[5]+=1;
else if(int(str[i])==54)
a[6]+=1;
else if(int(str[i])==55)
a[7]+=1;
else if(int(str[i])==56)
a[8]+=1;
else if(int(str[i])==57)
a[9]+=1;
}
int sum = 0;
for (int i =0;i<10;i++)
sum += i * a[i];
if (sum>=100)
cout<<strs[sum/100]<<' '<<strs[sum/10%10]<<' '<<strs[sum%10];
else if (sum >= 10)
cout<<strs[sum/10]<<' '<<strs[sum%10];
else
cout<<strs[sum];
}