当前位置:网站首页>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;
}
边栏推荐
- 1008 Elevator(20 分)(PAT甲级)
- FPGA timing constraint sharing 01_ Brief description of the four steps
- 双冒号作用运算符以及命名空间详解
- “只跑一趟”,小区装维任务主动推荐探索
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- 2021 合肥市信息学竞赛小学组
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
- 如何使用Async-Awati异步任務處理代替BackgroundWorker?
- Online sql to excel (xls/xlsx) tool
- 92.(cesium篇)cesium楼栋分层
猜你喜欢
随机推荐
测试工程师如何“攻城”(下)
牛客小白月赛7 谁是神箭手
Unity editor extends C to traverse all pictures in folders and subdirectories
Lm10 cosine wave homeopathic grid strategy
有关架构设计的个人思考(本文后续不断修改更新)
HDU 1097 A hard puzzle
LeetCode 赎金信 C#解答
MySQL数据库基本操作-DDL | 黑马程序员
“只跑一趟”,小区装维任务主动推荐探索
Shell programming core technology II
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
Generate XML elements
Shell 编程核心技术《二》
Summary and sorting of 8 pits of redis distributed lock
YOLOv5s-ShuffleNetV2
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
1003 Emergency(25 分)(PAT甲级)
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Use canal and rocketmq to listen to MySQL binlog logs








