• pat1005


    1005. Spell It Right (20)

    时间限制
    400 ms
    内存限制
    65536 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
    

    提交代码

    #include<iostream>
    #include<vector>
    #include<cstdio>
    #include<string.h>
    #include<string>
    using namespace std;
    string b[100];
    int main()
    {
        b[1]="one",b[2]="two",b[3]="three",b[4]="four",b[5]="five",b[6]="six",b[7]="seven",b[8]="eight",b[9]="nine",b[0]="zero";
        char a[1000];
        gets(a);
        int t=strlen(a);
        int sum=0;
    
        for(int i=0;i<t;i++)
        {
            sum=sum+(a[i]-'0');
    
        }
       int c[10000];
        int i=0;
       while(sum>0)
       {
           c[i]=sum%10;
           sum=sum/10;
           i++;
       }
       i--;
       for(;i>0;i--)
       {
          cout<<b[c[i]]<<" ";
       }
       cout<<b[c[0]]<<endl;
        return 0;
    }
  • 相关阅读:
    [JZOJ3339]【NOI2013模拟】wyl8899和法法塔的游戏
    [JZOJ3337] 【NOI2013模拟】wyl8899的TLE
    UVA 1262 Password
    UVA 10820 Send a Table
    UVA 12716 GCD XOR
    UVA 10791
    UVA 10375 choose and divide (唯一分解定理)
    欧拉函数
    51 Nod 1069 Nim游戏
    51 Nod 1242 矩阵快速幂求斐波那契数列
  • 原文地址:https://www.cnblogs.com/2014slx/p/7797831.html
Copyright © 2020-2023  润新知