PAT甲级——A1005 Spell It Right
题目描述
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 <iostream> 2 #include <string> 3 #include <vector> 4 5 using namespace std; 6 7 int main() 8 { 9 vector<string>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 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· 程序员常用高效实用工具推荐,办公效率提升利器!
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 【译】WinForms:分析一下(我用 Visual Basic 写的)