Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (≤10100).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
PAT的痛点就在英语太差,唉,这道题思路很明了,自然方法也有很多。
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
string nums;
string str[10] = { "zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine" };
vector<string> v;
string eng_str;
int sum = 0;
cin >> nums;
for (int i = 0; i < nums.size(); i++)
sum += (int)(nums[i] - '0');
eng_str=to_string(sum);
for (int i = 0; i < eng_str.size()-1; i++)
cout << str[eng_str[i] - '0'] << ' ';
cout << str[eng_str[eng_str.size() - 1] - '0'] << endl;
return 0;
}
以后。。。简单题就不写了,权当练手了,还是当成总结类型的记录博客来写好了