PAT 1005. Spell It Right

PAT 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

代码如下

#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<string> map{"zero","one","two","three","four",
                       "five","six","seven","eight","nine"};
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
    sum+=s[i]-'0';
    s=to_string(sum);
    for(int i=0;i<s.size();i++)
    i>0?cout<<" "<<map[s[i]-'0']:cout<<map[s[i]-'0'];
    return 0;
}

原文地址:https://www.cnblogs.com/A-Little-Nut/p/8186209.html

时间: 2024-10-16 07:01:23

PAT 1005. Spell It Right的相关文章

PAT 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 w

PAT 1005. Spell It Right (注意考虑0的情况)

代码: #include<cstdio> #include<cstring> using namespace std; char s[10][20]; int main() { strcpy(s[0],"zero");//对字符数组赋值 strcpy(s[1],"one"); strcpy(s[2],"two"); strcpy(s[3],"three"); strcpy(s[4],"four

1005. Spell It Right (20) -PAT

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: E

1005. Spell It Right (20)——PAT (Advanced Level) Practise

题目信息: 1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 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 Specificat

PAT 1005

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: E

1005. Spell It Right

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: E

1005 Spell It Right (20)(20 分)

1005 Spell It Right (20)(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 l

PAT A1005 Spell It Right

PAT A1005 Spell It Right 题目描述: 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 l

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 li