1005 Spell It Right (20 分)
作者:互联网
1005 Spell It Right (20)(20 分)
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.
input
12345
out
one five
这题比较简单就是输入的一个整数,然后求每一位的和,然后英文输出
注意!要是和是10的整数倍,需要注意,第四个测试点就是这个
上代码
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
string num[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
int sum = 0;
string input;
char str[500];
cin>>input;
for(int i = 0; i < input.size(); i++){
sum += input[i] - '0';
}
sprintf(str, "%d", sum);
for(int i = 0; i < strlen(str); i++){
if(i != 0) cout<<" ";
cout << num[str[i] - '0'];
}
return 0;
}
标签:Right,20,int,sum,Spell,input,1005,include,line 来源: https://blog.csdn.net/The_worst/article/details/115459123