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 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.

  Sample Input:
  12345

  Sample Output:
  one five

参考代码:

 1 /****************************************************
 2 PAT A1005 Spell It Right
 3 ****************************************************/
 4 #include <iostream>
 5 #include <string>
 6
 7 using namespace std;
 8
 9 const string NUM_WORD[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
10
11 int main() {
12     int sum = 0;
13     string num;
14     string ans;
15
16     cin >> num;
17
18     for (int i = 0; i < num.size(); ++i) {
19         sum += num[i] - ‘0‘;
20     }
21
22     ans = to_string(sum);
23     for (int i = 0; i < ans.size(); ++i) {
24         cout << NUM_WORD[ans[i] - ‘0‘];
25         if (i != ans.size() - 1) {
26             cout << ‘ ‘;
27         }
28     }
29
30     return 0;
31 }

注意事项:

  无。

原文地址:https://www.cnblogs.com/mrdragon/p/11412323.html

时间: 2024-10-29 08:01:40

PAT A1005 Spell It Right的相关文章

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 li

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

A1005. 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 (<= 101

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

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

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 (Advanced Level) 1005. Spell It Right (20)

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<vector> using namespace std; const int maxn=100+10; char s[maxn]; int tmp[maxn],tot; char ans[15][7]={ "zero&q

PAT:1005. Spell It Right (20) AC

#include<stdio.h> #include<string.h> char alp[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; char str[1200];