当前位置:网站首页>1005 Spell It Right(20 分)(PAT甲级)
1005 Spell It Right(20 分)(PAT甲级)
2022-07-04 17:58:00 【相思明月楼】
Problem Description:
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
一道简单题,注意一下为0的情况
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char s[110];
string num[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
scanf("%s", s);
int sum = 0, len = strlen(s);
for(int i = 0; i < len; i++) {
sum += (s[i] - '0');
}
int t, k = 0;
string ans[110];
if(sum == 0) {
printf("zero\n");
} else {
while(sum) {
t = sum%10;
ans[k++] = num[t];
sum /= 10;
}
for(int i = k-1; i > 0; i--) {
cout<<ans[i]<<" ";
}
cout<<ans[0]<<endl;
}
return 0;
}
边栏推荐
- 牛客小白月赛7 I 新建 Microsoft Office Word 文档
- 删除字符串中出现次数最少的字符【JS,Map排序,正则】
- 2022CoCa: Contrastive Captioners are Image-Text Fountion Models
- 长城证券开户安全吗 买股票怎么开户
- 自由小兵儿
- Process of manually encrypt the mass-producing firmware and programming ESP devices
- redis分布式锁的8大坑总结梳理
- 如何使用Async-Awati异步任务处理代替BackgroundWorker?
- QT realizes interface sliding switching effect
- Hough transform Hough transform principle
猜你喜欢
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
物联网应用技术的就业前景和现状
Lm10 cosine wave homeopathic grid strategy
One question per day (2022-07-02) - Minimum refueling times
A method of using tree LSTM reinforcement learning for connection sequence selection
Oracle with as ORA-00903: invalid table name 多表报错
Detailed explanation of the binary processing function threshold() of opencv
PolyFit软件介绍
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
如何使用Async-Awati异步任務處理代替BackgroundWorker?
随机推荐
IBM WebSphere MQ retrieving messages
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
The 15th youth informatics competition in Shushan District in 2019
An example of multi module collaboration based on NCF
Shell programming core technology II
redis分布式锁的8大坑总结梳理
FPGA timing constraint sharing 01_ Brief description of the four steps
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
删除字符串中出现次数最少的字符【JS,Map排序,正则】
神经网络物联网平台搭建(物联网平台搭建实战教程)
Online sql to excel (xls/xlsx) tool
876. Intermediate node of linked list
node_exporter部署
LM10丨余弦波动顺势网格策略
Generate XML elements
基于NCF的多模块协同实例
Bi skills - permission axis
Lm10 cosine wave homeopathic grid strategy
Pytorch学习(四)
Oracle with as ORA-00903: invalid table name 多表报错