当前位置:网站首页>1005 spell it right (20 points) (pat a)
1005 spell it right (20 points) (pat a)
2022-07-04 19:37:00 【Acacia moon tower】
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
A simple question , Note that 0 The situation of
#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;
}
边栏推荐
- 【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
- Generate XML elements
- 1006 sign in and sign out (25 points) (PAT class a)
- 92.(cesium篇)cesium楼栋分层
- FPGA时序约束分享01_四大步骤简述
- Shell 编程核心技术《一》
- BI技巧丨权限轴
- An example of multi module collaboration based on NCF
- The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
- Have you guys ever used CDC direct Mysql to Clickhouse
猜你喜欢
Some thoughts on whether the judgment point is located in the contour
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
92.(cesium篇)cesium楼栋分层
BCG 使用之新建向导效果
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
MySQL数据库基本操作-DDL | 黑马程序员
如何使用Async-Awati异步任務處理代替BackgroundWorker?
C# 使用StopWatch测量程序运行时间
The 300th weekly match of leetcode (20220703)
To sort out messy header files, I use include what you use
随机推荐
Hough transform Hough transform principle
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
node_ Exporter deployment
反射(一)
Some thoughts on whether the judgment point is located in the contour
Generate XML elements
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
@transactional滥用导致数据源连接池耗尽问题
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Explicit random number
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
双冒号作用运算符以及命名空间详解
Matrix flip (array simulation)
TCP两次挥手,你见过吗?那四次握手呢?
1011 World Cup Betting (20 分)(PAT甲级)
矩阵翻转(数组模拟)
Qt实现界面滑动切换效果
Shell 编程核心技术《四》
Several methods of online database migration
HDU 6440 2018中国大学生程序设计网络选拔赛