1005. Spell It Right (20)
2017-06-16 10:22
435 查看
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 (<= 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> #include <map> #include <cstring> using namespace std; map<int, string> Map; int Array[105]; void init(){ Map[0] = "zero"; Map[1] = "one"; Map[2] = "two"; Map[3] = "three"; Map[4] = "four"; Map[5] = "five"; Map[6] = "six"; Map[7] = "seven"; Map[8] = "eight"; Map[9] = "nine"; } void Add(int array[], int num){ int sum = array[0] + num; int index = 0; while(sum > 9){ array[index++] = sum % 10; sum /= 10; sum = array[index] + sum; } array[index] = sum; } void output(int array[]){ int len = 102; while(!array[len--]); //从高位数组向低位遍历,第一个非零位即为该值的最高位 for(int i = len + 1; i > 0; i--){ cout << Map[array[i]] << " "; } cout << Map[array[0]] << endl; } int main(){ char c; init(); int sum = 0; while(1){ c = getchar(); if(c == '\n') break; Add(Array, c - '0'); } output(Array); }
相关文章推荐
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 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)(to_string)
- 1005. Spell It Right (20)
- [PAT甲级]1005. Spell It Right (20)(求数字各个位上的和,英文输出)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT: 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)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)