A-1005 Spell It Right (20 分)
作者:互联网
A-1005 Spell It Right (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 (≤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.
Sample Input:
12345
Sample Output:
one five
#include <string>
#include <iostream>
using namespace std;
int main(){
int i,j,w[100]={},sum=0;
string str;
string word[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
cin >> str;
for(i=0;str[i]!=NULL;i++){//计算每一位数的和
sum+=(str[i]-'0');
}
if(sum==0){//如果为0直接输出zero
cout << "zero";
return 0;
}
for(j=0;sum>0;j++){//sum的每一位拆分存入数组中
w[j]=sum%10;
sum/=10;
}
for(i=j-1;i>=0;i--){//输出
cout << word[w[i]];
if(i>0)cout << ' ';
}
return 0;
}
标签:case,10,Right,cout,sum,Spell,str,1005,line 来源: https://blog.csdn.net/GCWsuger/article/details/113617478