AcWing 1477. 拼写正确
题意:
给你一个数字。(最大到
1
0
100
10^{100}
10100)
要求:
你求出每一位的和sum,
之后输出这个sum的每一位,用英文输出。
反思:
看到大佬有一个to_string()函数少写几行。
string a = to_string(sum) ;
AC
# include <string>
# include <vector>
# include <iostream>
# include <algorithm>
# define sz(a) (int)a.size()
# define pb push_back
# define ALL(a) a.begin(),a.end()
using namespace std;
const string num[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
string s;
cin>>s;
vector<string>ans;
int res = 0;
for(int i = 0; i < sz(s); i ++ ) res += s[i]-'0';
if(!res)ans.pb(num[res]);
while(res){
ans.pb(num[res%10]);
res /=10;
}
reverse(ALL(ans));
for(auto x: ans)cout<<x<<' ';
return 0;
}