题目描述
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 (≤10100).
输出描述
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
思路
签到题,一看数据范围果断字符读入求出总和,然后按位取对应输出就好了
实现
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
vector<int> v;
ll sum;
char ch;
void print(int x){
if(x==0) printf("zero");
if(x==1) printf("one");
if(x==2) printf("two");
if(x==3) printf("three");
if(x==4) printf("four");
if(x==5) printf("five");
if(x==6) printf("six");
if(x==7) printf("seven");
if(x==8) printf("eight");
if(x==9) printf("nine");
}
int main(){
for(int i=0;;i++){
ch=getchar();
if(ch=='\n') break;
sum+=ch-'0';
}
if(!sum) return printf("zero"),0;
while(sum){
v.push_back(sum%10);
sum/=10;
}
for(int i=v.size()-1;i>=0;i--){
if(i!=v.size()-1) printf(" ");
print(v[i]);
}
return 0;
}