当前位置:网站首页>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;
}
边栏推荐
- HDU 1372 & POJ 2243 Knight moves (breadth first search)
- Explicit random number
- Shell programming core technology "four"
- ftp、sftp文件传输
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
- 26. Delete the duplicate item C solution in the ordered array
- Technologie de base de la programmation Shell IV
- Jetpack Compose 教程
- Mysql database basic operation -ddl | dark horse programmer
- Use canal and rocketmq to listen to MySQL binlog logs
猜你喜欢

BI技巧丨权限轴

Pointnet/Pointnet++点云数据集处理并训练

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Some thoughts on whether the judgment point is located in the contour

mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总

Bi skills - permission axis

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

FPGA时序约束分享01_四大步骤简述

Lm10 cosine wave homeopathic grid strategy

92.(cesium篇)cesium楼栋分层
随机推荐
西门子HMI下载时提示缺少面板映像解决方案
Functional interface
Pytest 可视化测试报告之 Allure
Shell programming core technology "three"
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
Find the nth power of 2
1006 Sign In and Sign Out(25 分)(PAT甲级)
生成XML元素
Generate XML elements
升级智能开关,“零火版”、“单火”接线方式差异有多大?
Jetpack Compose 教程
1002. A+b for Polynomials (25) (PAT class a)
欧拉函数
Swagger突然发癫
92.(cesium篇)cesium楼栋分层
Specify the character set to output
Wechat reading notes of "work, consumerism and the new poor"
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
长城证券开户安全吗 买股票怎么开户
Use canal and rocketmq to listen to MySQL binlog logs