// 1005_Spell It Right.cpp : 定义控制台应用程序的入口点。
//1005. Spell It Right (20)
//
//时间限制
//400 ms
//内存限制
//65536 kB
//代码长度限制
//16000 B
//判题程序
//Standard
//作者
//CHEN, Yue
//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.
//
//Sample Input:
//12345
//Sample Output:
//one five
#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "string.h"
#include "stdlib.h"
#include "string"
#include "algorithm"
using namespace std;
string digit[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
int d[100];
int main()
{
string a;
while(cin>>a){
int sum = 0;
for(int i = 0;i<a.length();i++){
sum += a[i] - '0';
}
int j = 0;
while(sum){
d[j++] = sum%10;
sum /= 10;
}
for(int i = j-1;i>0;i--){
cout<<digit[d[i]]<<" ";
}
cout<<digit[d[0]]<<endl;
}
return 0;
}
PAT_1005.Spell It Right
最新推荐文章于 2020-08-18 16:48:06 发布