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
结尾无空行
题目大意
给定一个十进制整数,将其各位数字相加得到和,再按拼音输出和的每一位数字
AC代码
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<char, string>dict{{'1', "one"}, {'2', "two"}, {'3', "three"}, {'4', "four"}, {'5', "five"}, {'6', "six"}, {'7', "seven"}, {'8', "eight"}, {'9', "nine"}, {'0', "zero"}};
int main(){
string number;
int sum;
cin >> number;
for(char c: number){
sum += int(c - '0');
}
string sum_ = to_string(sum);
for (int i = 0; i < sum_.size();i++){
if(i!=0)
cout << " ";
cout << dict[sum_[i]];
}
return 0;
}