标签:参考 style string out turn sample col mes task
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 (≤10?100??).
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
1 /**************************************************** 2 PAT A1005 Spell It Right 3 ****************************************************/ 4 #include <iostream> 5 #include <string> 6 7 using namespace std; 8 9 const string NUM_WORD[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; 10 11 int main() { 12 int sum = 0; 13 string num; 14 string ans; 15 16 cin >> num; 17 18 for (int i = 0; i < num.size(); ++i) { 19 sum += num[i] - ‘0‘; 20 } 21 22 ans = to_string(sum); 23 for (int i = 0; i < ans.size(); ++i) { 24 cout << NUM_WORD[ans[i] - ‘0‘]; 25 if (i != ans.size() - 1) { 26 cout << ‘ ‘; 27 } 28 } 29 30 return 0; 31 }
无。
标签:参考 style string out turn sample col mes task
原文地址:https://www.cnblogs.com/mrdragon/p/11412323.html