当前位置:网站首页>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;
}
边栏推荐
- Unity adds a function case similar to editor extension to its script, the use of ContextMenu
- 1008 Elevator(20 分)(PAT甲级)
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- 1011 World Cup Betting (20 分)(PAT甲级)
- 876. Intermediate node of linked list
- 牛客小白月赛7 谁是神箭手
- 与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
- BI技巧丨权限轴
- 牛客小白月赛7 F题
- Stream stream
猜你喜欢

Safer, smarter and more refined, Chang'an Lumin Wanmei Hongguang Mini EV?

C# 使用StopWatch测量程序运行时间
关于判断点是否位于轮廓内的一点思考

BI技巧丨权限轴

Pytorch学习(四)

There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks

To sort out messy header files, I use include what you use
牛客小白月赛7 谁是神箭手

TCP两次挥手,你见过吗?那四次握手呢?

Euler function
随机推荐
关于判断点是否位于轮廓内的一点思考
kotlin 条件控制
In flinksql, in addition to data statistics, is the saved data itself a state
Functional interface
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
线上数据库迁移的几种方法
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
反射(一)
92.(cesium篇)cesium楼栋分层
Allure of pytest visual test report
How to use async Awati asynchronous task processing instead of backgroundworker?
2021 Hefei informatics competition primary school group
测试工程师如何“攻城”(上)
1005 Spell It Right(20 分)(PAT甲级)
C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
Jetpack Compose 教程
Shell 編程核心技術《四》
Hough transform Hough transform principle
Master the use of auto analyze in data warehouse
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks