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
  • 相关阅读:
    Mysq数据库备份(win)
    Mysql保存中文乱码问题
    MySql常用操作
    win下 mysql远程连接设置
    windows下redis的使用
    栈和队列
    ffmpeg 常用命令
    nginx https配置模板
    openssl 、nginx生成配置自签名证书
    https、公钥,私钥,数字证书
  • 原文地址:https://www.cnblogs.com/57one/p/11858597.html
Copyright © 2011-2022 走看看