当前位置:网站首页>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 6440 2018 Chinese college student program design network competition
- 线上数据库迁移的几种方法
- HDU 1097 A hard puzzle
- Leetcode fizzbuzz C # answer
- Unity editor extends C to traverse all pictures in folders and subdirectories
- 在线文本行固定长度填充工具
- Online text line fixed length fill tool
- Several methods of online database migration
- FTP, SFTP file transfer
- node_ Exporter deployment
猜你喜欢
Summary and sorting of 8 pits of redis distributed lock
BCG 使用之CBCGPProgressDlg进度条使用
92. (cesium chapter) cesium building layering
PolyFit软件介绍
SSRS筛选器的IN运算(即包含于)用法
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
升级智能开关,“零火版”、“单火”接线方式差异有多大?
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Wireshark网络抓包
随机推荐
Find the nth power of 2
PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
Shell programming core technology "three"
函数式接口
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Shell programming core technology II
牛客小白月赛7 E Applese的超能力
node_ Exporter deployment
2021 合肥市信息学竞赛小学组
BCG 使用之新建向导效果
如何使用Async-Awati异步任务处理代替BackgroundWorker?
在线文本行固定长度填充工具
node_exporter部署
Shell programming core technology "I"
OpenCV的二值化处理函数threshold()详解
Online text line fixed length fill tool
Several methods of online database migration
1005 Spell It Right(20 分)(PAT甲级)
Detailed explanation of issues related to SSL certificate renewal