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:
12345Sample 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]
相关文章推荐
- 1005.Spell It Right (20)
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- PAT-Java-1005-Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT (Advanced Level) Practise 1005 Spell It Right (20)
- 1005. Spell It Right (20)
- (PAT)1005. Spell It Right (20)
- 1005. Spell It Right (20)——PAT (Advanced Level) Practise
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005 Spell It Right (20)
- PAT-A 1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)