PAT 同时被 2 个专栏收录
2 篇文章 0 订阅
9 篇文章 0 订阅

# P1005 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




#include <cstdio>

#include <iostream>

#include <string>

#define maxN 101

using namespace std;

int main()

{

string num[10] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

long int sum = 0;

char c;

while ((c=getchar())!='\n')

{

sum += c - '0';

}

int s[maxN], length = 0,t=sum;

while (t!=0)

{

s[length++] = t % 10;

t /= 10;

}

//针对sum=0的情况进行处理

if (sum == 0)

{

printf("zero");

return 0;

}

cout << num[s[length - 1]];

for (int i = length - 2; i >= 0; i--)

{

printf(" ");

cout << num[s[i]];

}

//system("pause");

}


• 0
点赞
• 0
评论
• 0
收藏
• 打赏
• 扫一扫，分享海报

07-25

07-26 82
07-26 38
02-18 457
05-04 32
02-12 58
01-12 642
01-18 48
©️2022 CSDN 皮肤主题：书香水墨 设计师：CSDN官方博客

vcjmhg

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。