题目大意
给出一个数,把它的和加起来。然后再用英语来表达出他的和。
解决方法
通过字符串来进行加减,然后再利用哈希表来进行查值输出。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <cstdio> #include <map> #include <cmath> #include <set> #include <stack> #include <queue>
using namespace std; const int maxn=100100;
int main() { string string1; cin>>string1; int ans=0; for (int i = 0; i < string1.length(); ++i) { ans+=string1[i]-'0'; } string string2=to_string(ans); string out[10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; for (int j = 0; j < string2.length(); ++j) { if (j==0){ cout<<out[string2[j]-'0']; } else{ cout<<" "<<out[string2[j]-'0'];
} } return 0; }
|