您的位置:首页 > 其它

1005. Spell It Right (20)

2014-11-09 22:47 483 查看
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 <iostream>#include <cstdio>using namespace std;char digit[10][6] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};int main(void){char str[101];while (scanf("%s", str)!= EOF){int i = 0;int sum = 0;while (str[i])sum += str[i++] - '0';int num[3]; //sum最大值为900,只需要存储个十百位就可以了int index = 0;if (sum == 0) //需要提前判断是否为0num[index++] = 0;while (sum){num[index++] = sum % 10;sum /= 10;}for (int i = index - 1; i > 0; --i)printf("%s ", digit[num[i]]);printf("%s\n", digit[num[0]]);}return 0;}
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: