PAT-A-1005. Spell It Right (20)
2017-04-04 20:02
375 查看
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<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
int sum, num;
sum = num = 0;
int r[5] = { 0 };
string s[10] = { "zero", "one", "two", "three", "four", "five","six", "seven", "eight", "nine" };
string d;
getline(cin,d);
for (int i = 0; i < d.length(); i++)
{
sum += d[i] - '0';
}
if (sum == 0)
{
cout << s[0];
return 0;
}
//cout << sum;
while (sum != 0)
{
r[++num] = sum % 10;
sum = sum / 10;
}
int flag = 1;
for (int i = num; i >= 1; i--)
{
if (flag)
{
flag = 0;
cout << s[r[i]];
}
else
cout << " " << s[r[i]];
}
system("pause");
return 0;
}
相关文章推荐
- PAT (Advanced Level) 1005. Spell It Right (20) string转int,哈希
- PAT (Advanced Level) 1005. Spell It Right (20)
- PAT---1005. Spell It Right (20)
- 【PAT甲级】【C++】1005. Spell It Right (20)
- 浙江大学PAT上机题解析之1005. Spell It Right (20)
- 【PAT】1005. Spell It Right (20)
- [PAT] 1005 Spell It Right (20)
- PAT1005. Spell It Right (20)
- 1005. Spell It Right (20) PAT甲级刷题
- PAT 甲 1005. Spell It Right (20)
- PAT:A1005. Spell It Right (20/20)
- PAT: 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- 【c++】PAT (Advanced Level) 1005. Spell It Right (20)
- PAT(甲级)-1005. Spell It Right (20)
- PAT_A 1005. Spell It Right (20)
- pat 1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- 【PAT Advanced Level】1005. Spell It Right (20)
- PAT 1005. Spell It Right(20)