• 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 (≤).

    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

     1 #include<iostream>
     2 #include<string>
     3 #include<stdlib.h>
     4 #include<vector>
     5 using namespace std;
     6 char str[10][10] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
     7 int main()
     8 {
     9     int digit[20] = { 0 };
    10     char c;
    11     int num = 0;
    12     c = getchar();
    13     while (c!='
    ')
    14     {
    15         num += c - '0';
    16         c = getchar();
    17     }
    18     int i=0;
    19     if (!num)
    20     {
    21         printf("%s", str[0]);
    22         return 0;
    23     }
    24     while (num)
    25     {
    26         digit[i++] = num % 10;
    27         num /= 10;
    28     }
    29     while (--i)
    30         printf("%s ", str[digit[i]]);
    31     printf("%s", str[digit[i]]);
    32     return 0;
    33 }
    View Code
  • 相关阅读:
    第10组 Beta冲刺(2/5)
    第10组 Beta冲刺(1/5)
    第10组 Alpha事后诸葛亮
    3月7-第十次机试课记录
    3月5-第九次机试课记录
    3月2-第八次机试课记录
    3月1-第六次机试课记录
    2月28-第五次机试课记录
    STL
    2月27-第四次机试课记录
  • 原文地址:https://www.cnblogs.com/57one/p/11858597.html
Copyright © 2020-2023  润新知