1005. Spell It Right (20)

来源:互联网 发布:数据中心与云计算 编辑:程序博客网 时间:2024/06/03 23:42

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

提交代码

http://www.patest.cn/contests/pat-a-practise/1005

#include <cstdio>  #include <iostream>#include <cstring>#include <string>#include <sstream>#include <vector>#include <queue>using namespace std;#define N 1000string sn[] = {"zero" ,"one" , "two" ,"three" ,"four" ,  "five" ,"six" ,"seven" ,"eight" ,"nine"};char s[N] ;int main(){  //freopen("in.txt" , "r" , stdin) ;  while(scanf("%s" , s) != EOF)  {    int sum = 0 ;    for(int i = 0 ; i < strlen(s) ; i++)    {      int num = s[i] - '0' ;      sum += num ;    }    stringstream ss ;    ss << sum ;    string stmp ;    ss >> stmp ;    int len = stmp.size() ;    int index = stmp[0] - '0' ;    cout << sn[index] ;    for(int i = 1 ; i < len ; i++)    {      index = stmp[i] - '0' ;      cout << " " << sn[index] ;    }    printf("\n") ;  }  return 0 ;}


0 0