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
题目大意
给你一个int数字,要求你按照位相加得到sum,然后用英文输出每位数字。
解题过程
这是一道字符串处理的题目,用到的知识点如下图
AC代码
#include<iostream>
#include<string>
#include<vector>
using namespace std;
vector<string> str={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{
string a;
cin>>a;
int sum=0;
for(int i=0;i<a.size();i++)
{
char s = a[i];
sum += (s-'0');
}
string s = to_string(sum);
for(int i =0;i<s.size();i++)
{
if(i) cout<<" ";
cout<<str[(s[i]-'0')];
}
return 0;
}