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
  • 相关阅读:
    Solidity 官方文档中文版 3_安装Solidity
    javaweb监听器
    ssh基础配置大全
    servlet
    压缩介绍
    jsp小结
    servlet生命周期
    后台权限验证
    进程&线程
    StrutsPreparedAndExcuteFilter与Interceptor
  • 原文地址:https://www.cnblogs.com/57one/p/11858597.html
Copyright © 2011-2022 走看看