1005 Spell It Right(20 分)
1005 Spell It Right(20 分)
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
1 #include <map> 2 #include <set> 3 #include <queue> 4 #include <cmath> 5 #include <stack> 6 #include <vector> 7 #include <string> 8 #include <cstdio> 9 #include <cstring> 10 #include <climits> 11 #include <iostream> 12 #include <algorithm> 13 #define wzf ((1 + sqrt(5.0)) / 2.0) 14 #define INF 0x3f3f3f3f 15 #define LL long long 16 using namespace std; 17 18 const int MAXN = 105; 19 20 char s[MAXN]; 21 int ans; 22 23 stack <int> st; 24 map <int, string> mp; 25 26 int main() 27 { 28 mp[0] = "zero"; 29 mp[1] = "one"; 30 mp[2] = "two"; 31 mp[3] = "three"; 32 mp[4] = "four"; 33 mp[5] = "five"; 34 mp[6] = "six"; 35 mp[7] = "seven"; 36 mp[8] = "eight"; 37 mp[9] = "nine"; 38 scanf("%s", &s); 39 40 int len = strlen(s); 41 for (int i = 0; i < len; ++ i) 42 ans += int(s[i] - '0'); 43 if (ans == 0) 44 { 45 printf("zero\n"); 46 return 0; 47 } 48 while (ans) 49 { 50 st.push(ans % 10); 51 ans /= 10; 52 } 53 while (st.size() > 1) 54 { 55 cout <<mp[st.top()] <<" "; 56 st.pop(); 57 } 58 cout <<mp[st.top()] <<endl; 59 st.pop(); 60 return 0; 61 }
分类:
Pat
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞