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.
简单模拟,将给定的字符串的各个位置相加,用字符串的方式输出和。
#include <bits/stdc++.h>
using namespace std;
void get (int x)
{
if (x==0) cout << "zero";
if (x==1) cout << "one";
if (x==2) cout << "two";
if (x==3) cout << "three";
if (x==4) cout << "four";
if (x==5) cout << "five";
if (x==6) cout << "six";
if (x==7) cout << "seven";
if (x==8) cout << "eight";
if (x==9) cout << "nine";
}
int main()
{
string s;
cin >> s;
int sum = 0;
for (int i = 0 ;i<s.length();i++)
{
sum+=s[i]-48;
}
string t = to_string(sum);
for(int i = 0; i < t.size(); i++) {
if(i != 0) putchar(' ');
get(t[i]-48);
}
return 0;
}