博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT甲级——A1005 Spell It Right
阅读量:4542 次
发布时间:2019-06-08

本文共 1097 字,大约阅读时间需要 3 分钟。

题目描述

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.

 

输入描述:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

输出描述:

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.

 

输入例子:

12345

 

输出例子:

one five 太简单了。。。。
1 #include 
2 #include
3 #include
4 5 using namespace std; 6 7 int main() 8 { 9 vector
words = { "zero","one","two","three","four","five","six","seven","eight","nine","ten" };10 string num;//不能用数字类型存储,会导致溢出的11 cin >> num;12 int sum = 0;13 for (auto a : num)14 sum += a - '0';15 num = to_string(sum);16 cout << words[num[0] - '0'];17 for (int i = 1; i < num.length(); ++i)18 cout << " " << words[num[i] - '0'];19 cout << endl;20 return 0;21 }

 

转载于:https://www.cnblogs.com/zzw1024/p/11172364.html

你可能感兴趣的文章
Git学习总结
查看>>
穿透防火墙的数据传输新技术
查看>>
Button加在UITableViewHeaderFooterView的self.contentView上导致不能响应点击
查看>>
TinkerPop中的遍历:图的遍历策略
查看>>
shell入门-sort排序
查看>>
[转]BT原理分析
查看>>
通过httpClient请求文件流(普通文件和压缩文件)示例
查看>>
max10之pll时钟源切换
查看>>
Android框架总结
查看>>
vue基础课堂一
查看>>
1Password:让一个密码记住所有密码
查看>>
Python 元组
查看>>
Android——四大组件、六大布局、五大存储
查看>>
Socket实现原理和机制
查看>>
luogu1265 公路修建
查看>>
WORD2003电子签名插件(支持手写、签章)
查看>>
Google开源项目二维码读取与生成工具ZXing
查看>>
Android使用默认样式创建View的几个姿势
查看>>
多标记学习--Learning from Multi-Label Data
查看>>
leetcode 47. 全排列 II
查看>>