zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    一些可以参考的常用工具库类整理
    Java(Android)线程池 总结
    JAVA泛型
    设计模式总结
    原型模式
    工厂模式与抽象工厂模式
    组合模式
    适配器模式
    建造者模式
    外观模式
  • 原文地址:https://www.cnblogs.com/57one/p/11858597.html
Copyright © 2011-2022 走看看