1005 Spell It Right (20分)

Posted f4lc0n

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

题意:

计算数字N的每一位合,然后用英语读每一位。

题解:

#include <iostream>
using namespace std;

int main() {
    long long sum = 0;
    string n;
    cin >> n;
    for(int i=0;i<n.size();i++) sum+=(n[i]-'0');
    string ans = to_string(sum);
    string tamp[10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
    for(int i=0;i<ans.size();i++) {
        if(i) cout << " ";
        cout << tamp[ans[i]-'0'];
    }
    return 0;
}

以上是关于1005 Spell It Right (20分)的主要内容,如果未能解决你的问题,请参考以下文章

PAT 甲级 1005 Spell It Right (20 分)

1005 Spell It Right (20 分)难度: 简单 / 知识点: 模拟

1005. Spell It Right (20)

1005 Spell It Right

1005. Spell It Right (20)

1005. Spell It Right (20)