zoukankan      html  css  js  c++  java
  • 1005. Spell It Right

    1005. Spell It Right (20)

    时间限制
    400 ms
    内存限制
    32000 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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
     1 #include <iostream>
    2 #include <fstream>
    3 #include <vector>
    4 #include <string>
    5 #include <algorithm>
    6 #include <map>
    7 #include <stack>
    8 #include <cmath>
    9 #include <queue>
    10 #include <set>
    11
    12
    13 using namespace std;
    14
    15
    16
    17
    18 int main()
    19 {
    20
    21
    22
    23 map<char , int> char2int;
    24 map<char,string> int2EN;
    25
    26 for( int i = 0 ; i < 10 ; ++i )
    27 {
    28 char2int[(char)('0' + i)] = i;
    29 }
    30
    31 int2EN['0'] = "zero";
    32 int2EN['1'] = "one";
    33 int2EN['2'] = "two";
    34 int2EN['3'] = "three";
    35 int2EN['4'] = "four";
    36 int2EN['5'] = "five";
    37 int2EN['6'] = "six";
    38 int2EN['7'] = "seven";
    39 int2EN['8'] = "eight";
    40 int2EN['9'] = "nine";
    41
    42 char ch;
    43 int sum = 0;
    44 while(1)
    45 {
    46 ch = cin.get();
    47
    48 if( ch >= '0' && ch <= '9' )
    49 {
    50 sum += char2int[ch];
    51 }
    52 else
    53 {
    54 break;
    55 }
    56 }
    57
    58 char buff[50];
    59
    60 sprintf( buff , "%d" , sum );
    61
    62 for( int i = 0 ; i < 50 ; ++i )
    63 {
    64 if(buff[i] == '\0')
    65 {
    66 break;
    67 }
    68 else
    69 {
    70 if( i != 0 )
    71 {
    72 printf(" ");
    73 }
    74 printf("%s" , int2EN[buff[i]].c_str());
    75 }
    76 }
    77 cout << endl;
    78
    79
    80 return 0;
    81 }


  • 相关阅读:
    Kafka 再均衡监听器示例
    Spring boot中异步线程池
    【Java&Go并发编程系列】4.等待一组并发任务完成——CountDownLatch VS sync.WaitGroup
    Redis常用命令对应到Redisson对象操作
    js清空缓存,ajax
    phpexcel用法 转、
    composer 使用
    转:git操作
    手机微信内支付
    微信扫码支付
  • 原文地址:https://www.cnblogs.com/kking/p/2331830.html
Copyright © 2011-2022 走看看