题目
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.
输入
Each input file contains one test case.
Each case occupies one line which contains an N (≤).
输出
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.
样例输入
12345
样例输出
one five
题意理解
题意是给你一个数字n,小于等于10的100次方幂,算出这个数字各个位数的和,将和的各个位数输出成英文。题目很简单,大致模拟一下这个过程即可,注意的是n很大,所以我们用字符串来读入。
代码
#include<bits/stdc++.h>
using namespace std;
string ss;
map<char,string>ma;
vector<int>ve;
int main(){
ma['0']="zero";
ma['1']="one";
ma['2']="two";
ma['3']="three";
ma['4']="four";
ma['5']="five";
ma['6']="six";
ma['7']="seven";
ma['8']="eight";
ma['9']="nine";
cin>>ss;
int sum=0;
for(int i=0;i<ss.size();i++){
if(ss[i]>='0'&&ss[i]<='9'){
sum+=ss[i]-'0';
}
}
string s=to_string(sum);
for(int i=0;i<s.size();i++){
if(i)printf(" ");
cout<<ma[s[i]];
}
return 0;
}