当前位置:网站首页>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;
}
边栏推荐
- 有关架构设计的个人思考(本文后续不断修改更新)
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- Detailed explanation of issues related to SSL certificate renewal
- The 300th weekly match of leetcode (20220703)
- Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
- Bi skills - permission axis
- Educational Codeforces Round 22 E. Army Creation
- 牛客小白月赛7 谁是神箭手
- Pytest 可视化测试报告之 Allure
- English grammar_ Noun - use
猜你喜欢
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
Some thoughts on whether the judgment point is located in the contour
Introduction to polyfit software
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
西门子HMI下载时提示缺少面板映像解决方案
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
Oracle with as ORA-00903: invalid table name 多表报错
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Mysql database basic operation -ddl | dark horse programmer
Online text line fixed length fill tool
随机推荐
kotlin 条件控制
Generate XML elements
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
Have you guys ever used CDC direct Mysql to Clickhouse
Hough transform Hough transform principle
@transactional滥用导致数据源连接池耗尽问题
Stream stream
Use canal and rocketmq to listen to MySQL binlog logs
添加命名空间声明
HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
Leetcode fizzbuzz C # answer
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
YOLOv5s-ShuffleNetV2
BCG 使用之CBCGPProgressDlgCtrl進度條使用
English语法_名词 - 使用
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Bi skills - permission axis
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
Specify the character set to output
In flinksql, in addition to data statistics, is the saved data itself a state