当前位置:网站首页>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;
}
边栏推荐
- Educational Codeforces Round 22 E. Army Creation
- SSRS筛选器的IN运算(即包含于)用法
- Online text line fixed length fill tool
- The kth largest element in the array
- Functional interface
- Jetpack Compose 教程
- Wechat reading notes of "work, consumerism and the new poor"
- Hough Transform 霍夫变换原理
- Introduction to polyfit software
- There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
猜你喜欢

LM10丨余弦波动顺势网格策略

Pytorch学习(四)

Swagger突然发癫

升级智能开关,“零火版”、“单火”接线方式差异有多大?

2022CoCa: Contrastive Captioners are Image-Text Fountion Models

SSRS筛选器的IN运算(即包含于)用法
Summary and sorting of 8 pits of redis distributed lock

The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize

联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点

How to use async Awati asynchronous task processing instead of backgroundworker?
随机推荐
2021 合肥市信息学竞赛小学组
26. Delete the duplicate item C solution in the ordered array
升级智能开关,“零火版”、“单火”接线方式差异有多大?
Have you guys ever used CDC direct Mysql to Clickhouse
Generate XML elements
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
English grammar_ Noun - use
LeetCode 赎金信 C#解答
Add namespace declaration
YOLOv5s-ShuffleNetV2
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
@transactional滥用导致数据源连接池耗尽问题
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
生成XML元素
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
牛客小白月赛7 F题
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
矩阵翻转(数组模拟)