其他分享
首页 > 其他分享> > 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 (≤10^100).

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.
在这里插入图片描述代码如下:

#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<algorithm>
#include<typeinfo>
using namespace std;

void Read(int t,bool space);
int main()
{
    string N;
    cin>>N;
    long long s = 0;
    int size = N.length();
    
    for(int i=0;i<size;i++)
    {
        int t = N[i] - '0';
        s += t;
    }
    stringstream ss;
    ss << s;
    ss >> N;
    
    size = N.length();
    int c = N[0] - '0';
    Read(c,false);
    
    for(int i=1;i<size;i++)
    {
        Read(N[i]-'0',true);
    }
    
    return 0;
}

void Read(int t,bool space)
{
    if(space)    cout<<" ";
    switch(t)
    {
        case 0:
            cout<<"zero";
            break;
        case 1:
            cout<<"one";
            break;
        case 2:
            cout<<"two";
            break;
        case 3:
            cout<<"three";
            break;
        case 4:
            cout<<"four";
            break;
        case 5:
            cout<<"five";
            break;
        case 6:
            cout<<"six";
            break;
        case 7:
            cout<<"seven";
            break;
        case 8:
            cout<<"eight";
            break;
        case 9:
            cout<<"nine";
            break;
    }
}

标签:case,Right,space,int,sum,Spell,Read,1005,include
来源: https://blog.csdn.net/m0_46320667/article/details/121367568