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<iostream>
#include<cstring>
using namespace std;
string Num;
void input()
{
cin>>Num;
//计算位数
int s=0;
for(int i=0;i<Num.size();i++){
s+=Num[i]-'0';
}
string R=to_string(s);
for(int i=0;i<R.size();i++)
{
switch(R[i]){
case '1':
cout<<"one";
break;
case'2':
cout<<"two";
break;