zoukankan      html  css  js  c++  java
  • 1005 Spell It Right(20 分)

    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 (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 <map>
     2 #include <set>
     3 #include <queue>
     4 #include <cmath>
     5 #include <stack>
     6 #include <vector>
     7 #include <string>
     8 #include <cstdio>
     9 #include <cstring>
    10 #include <climits>
    11 #include <iostream>
    12 #include <algorithm>
    13 #define wzf ((1 + sqrt(5.0)) / 2.0)
    14 #define INF 0x3f3f3f3f
    15 #define LL long long
    16 using namespace std;
    17 
    18 const int MAXN = 105;
    19 
    20 char s[MAXN];
    21 int ans;
    22 
    23 stack <int> st;
    24 map <int, string> mp;
    25 
    26 int main()
    27 {
    28     mp[0] = "zero";
    29     mp[1] = "one";
    30     mp[2] = "two";
    31     mp[3] = "three";
    32     mp[4] = "four";
    33     mp[5] = "five";
    34     mp[6] = "six";
    35     mp[7] = "seven";
    36     mp[8] = "eight";
    37     mp[9] = "nine";
    38     scanf("%s", &s);
    39 
    40     int len = strlen(s);
    41     for (int i = 0; i < len; ++ i)
    42         ans += int(s[i] - '0');
    43     if (ans == 0)
    44     {
    45         printf("zero
    ");
    46         return 0;
    47     }
    48     while (ans)
    49     {
    50         st.push(ans % 10);
    51         ans /= 10;
    52     }
    53     while (st.size() > 1)
    54     {
    55         cout <<mp[st.top()] <<" ";
    56         st.pop();
    57     }
    58     cout <<mp[st.top()] <<endl;
    59     st.pop();
    60     return 0;
    61 }
     
  • 相关阅读:
    Python 集合
    Python sorted()
    CodeForces 508C Anya and Ghosts
    CodeForces 496B Secret Combination
    CodeForces 483B Friends and Presents
    CodeForces 490C Hacking Cypher
    CodeForces 483C Diverse Permutation
    CodeForces 478C Table Decorations
    CodeForces 454C Little Pony and Expected Maximum
    CodeForces 313C Ilya and Matrix
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9576599.html
Copyright © 2011-2022 走看看