标签:test rds input seve namespace contain for ++ bsp
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:12345Sample Output:
one five
思路
1.10^100位数字,用字符串输入就行。
2.用vector保存下每个数字对应的单词
2.因为题目原因,实际最大也就101个数字加起来,最大不会超过909,所以可以用int保存数字。
3.int转为字符串,输出串每一位数字对应的单词就行。
代码
#include<iostream> #include<vector> using namespace std; vector<string> numbers = { "zero","one","two","three","four","five","six","seven","eight","nine" }; int main() { string n; while(cin >> n) { int sum = 0; for(int i = 0;i < n.size();i++) { sum += (n[i] - ‘0‘); } string s = to_string(sum); cout << numbers[s[0] - ‘0‘]; for(int i = 1; i < s.size();i++) { cout << " " << numbers[s[i] - ‘0‘]; } } }
标签:test rds input seve namespace contain for ++ bsp
原文地址:http://www.cnblogs.com/0kk470/p/7625819.html