当前位置:网站首页>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;
}
边栏推荐
- The 15th youth informatics competition in Shushan District in 2019
- Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
- Hough Transform 霍夫变换原理
- Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
- 牛客小白月赛7 I 新建 Microsoft Office Word 文档
- 长城证券开户安全吗 买股票怎么开户
- Educational Codeforces Round 22 E. Army Creation
- The 300th weekly match of leetcode (20220703)
- 2021 Hefei informatics competition primary school group
- 测试工程师如何“攻城”(下)
猜你喜欢
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
FPGA时序约束分享01_四大步骤简述
线上数据库迁移的几种方法
Pointnet/Pointnet++点云数据集处理并训练
The 300th weekly match of leetcode (20220703)
C# 使用StopWatch测量程序运行时间
How to use async Awati asynchronous task processing instead of backgroundworker?
Stream流
English grammar_ Noun - use
Lm10 cosine wave homeopathic grid strategy
随机推荐
Pytest 可视化测试报告之 Allure
HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
Find the nth power of 2
92.(cesium篇)cesium楼栋分层
Reflection (I)
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Euler function
LeetCode 赎金信 C#解答
有关架构设计的个人思考(本文后续不断修改更新)
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
OpenCV的二值化处理函数threshold()详解
Wechat reading notes of "work, consumerism and the new poor"
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
Detailed explanation of the binary processing function threshold() of opencv
Leetcode ransom letter C # answer
牛客小白月赛7 谁是神箭手
Shell 编程核心技术《三》
ftp、sftp文件传输
矩阵翻转(数组模拟)