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 }
     
  • 相关阅读:
    2014年互联网发展趋势如何
    服务器出现阶段性错误
    用互联网思想武装自己
    杭州互联网公司汇总
    互联网牛人网址大全
    ffmpeg开发指南
    Windows下FFmpeg快速入门
    FFmpeg介绍及参数详细说明
    windows 下FFMPEG的编译方法 附2012-9-19发布的FFMPEG编译好的SDK下载
    FFMPEG视音频编解码零基础学习方法 【荐】
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9576599.html
Copyright © 2011-2022 走看看