1477. 拼写正确
作者:
lvjj
,
2024-03-16 20:48:15
,
所有人可见
,
阅读 12
//各个位的字符串转成数字,将数字都加起来
//将数字转化为字符串,将各个位的字符与字典对应,然后输出
#include <bits/stdc++.h>
using namespace std;
string str;
int sum = 0;
string str1;
int main(){
cin>>str;
for(int i = 0;i < str.size();i++){
sum += str[i]-48;
}
str1 = to_string(sum);
for(int i=0;i<str1.size();i++){
if(str1[i]=='0')cout<<"zero"<<" ";//改进:用一个string存这些可能的映射会减少更多代码
else if(str1[i]=='1')cout<<"one"<<" ";
else if(str1[i]=='2')cout<<"two"<<" ";
else if(str1[i]=='3')cout<<"three"<<" ";
else if(str1[i]=='4')cout<<"four"<<" ";
else if(str1[i]=='5')cout<<"five"<<" ";
else if(str1[i]=='6')cout<<"six"<<" ";
else if(str1[i]=='7')cout<<"seven"<<" ";
else if(str1[i]=='8')cout<<"eight"<<" ";
else if(str1[i]=='9')cout<<"nine"<<" ";
}
return 0;
}