题目很简单,但是要注意输入的范围是10^100,int,long long都不能存,只能创建一个字符串.
1 #include<iostream> 2 #include<vector> 3 #include<queue> 4 #include<map> 5 #include<set> 6 #include<cmath> 7 #include<cstdio> 8 #include<cstdlib> 9 #include<cstring> 10 #include<algorithm> 11 using namespace std; 12 13 string digit[10] = { "zero","one","two","three","four","five","six","seven","eight","nine" }; 14 string N; 15 16 int main() 17 { 18 while (cin >> N) { 19 if (N == "0") { 20 cout << digit[0] << endl; 21 continue; 22 } 23 long long M = 0; 24 vector<int> stack; 25 for (auto ch : N) M += (ch - '0'); 26 while (M) { 27 stack.push_back(M % 10); 28 M /= 10; 29 } 30 int n = stack.size(); 31 cout << digit[stack[n - 1]]; 32 for (int i = n - 2; i >= 0; i--) cout << " " << digit[stack[i]]; 33 cout << endl; 34 } 35 return 0; 36 }