当前位置:网站首页>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;
}
边栏推荐
- 更安全、更智能、更精致,长安Lumin完虐宏光MINI EV?
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- Nebula importer data import practice
- Pytorch学习(四)
- Wireshark网络抓包
- prometheus安装
- Shell 编程核心技术《四》
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- Introduction to polyfit software
- Oracle with as ora-00903: invalid table name multi report error
猜你喜欢
Summary and sorting of 8 pits of redis distributed lock
升级智能开关,“零火版”、“单火”接线方式差异有多大?
如何使用Async-Awati异步任务处理代替BackgroundWorker?
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Oracle with as ORA-00903: invalid table name 多表报错
在线文本行固定长度填充工具
OpenCV的二值化处理函数threshold()详解
小发猫物联网平台搭建与应用模型
Hough Transform 霍夫变换原理
Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
随机推荐
在线文本行固定长度填充工具
Pytest 可视化测试报告之 Allure
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
2019年蜀山区第十五届青少年信息学竞赛
偏移量函数及开窗函数
1006 Sign In and Sign Out(25 分)(PAT甲级)
2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Leetcode ransom letter C # answer
Use canal and rocketmq to listen to MySQL binlog logs
FPGA timing constraint sharing 01_ Brief description of the four steps
神经网络物联网平台搭建(物联网平台搭建实战教程)
The latest progress of Intel Integrated Optoelectronics Research promotes the progress of CO packaging optics and optical interconnection technology
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Shell 编程核心技术《一》
Lm10 cosine wave homeopathic grid strategy
大佬们,求助一下,我用mysql cdc 2.2.1(flink 1.14.5)写入kafka,设置
性能优化之关键渲染路径
Go microservice (II) - detailed introduction to protobuf