当前位置:网站首页>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;
}
边栏推荐
- Detailed explanation of the binary processing function threshold() of opencv
- Shell 编程核心技术《四》
- 876. Intermediate node of linked list
- Go微服务(二)——Protobuf详细入门
- Summary and sorting of 8 pits of redis distributed lock
- 整理混乱的头文件,我用include what you use
- 关于判断点是否位于轮廓内的一点思考
- 牛客小白月赛7 I 新建 Microsoft Office Word 文档
- 物联网应用技术的就业前景和现状
- 牛客小白月赛7 F题
猜你喜欢
redis分布式锁的8大坑总结梳理
Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?
Oracle with as ORA-00903: invalid table name 多表报错
FPGA时序约束分享01_四大步骤简述
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
Wireshark网络抓包
node_exporter部署
Nebula importer data import practice
一文掌握数仓中auto analyze的使用
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
随机推荐
Use canal and rocketmq to listen to MySQL binlog logs
Oracle with as ORA-00903: invalid table name 多表报错
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
876. 链表的中间结点
26. Delete the duplicate item C solution in the ordered array
Unity editor extends C to traverse all pictures in folders and subdirectories
Using SSH
Leetcode fizzbuzz C # answer
Detailed explanation of the binary processing function threshold() of opencv
1011 World Cup Betting (20 分)(PAT甲级)
1002. A+B for Polynomials (25)(PAT甲级)
Leetcode ransom letter C # answer
Shell programming core technology "four"
How test engineers "attack the city" (Part 2)
Hough transform Hough transform principle
Cache é JSON uses JSON adapters
BI技巧丨权限轴
生成XML元素
FPGA timing constraint sharing 01_ Brief description of the four steps
1672. Total assets of the richest customers