PAT1005. Spell It Right (20)
来源:互联网 发布:农村淘宝网址 编辑:程序博客网 时间:2024/06/05 21:51
1005. Spell It Right (20)
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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:12345Sample Output:
one five
很简单的一个basic程序
#include <iostream>#include <algorithm>#include <string>#include <stack>using namespace std;stack <int> stk;string nm[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};int get_len(int n){ if(n == 0) return 1; int len = 0; while(n) { n /= 10; len++; } return len;}void set_stk(int n){ if(n == 0) { stk.push(0); return; } while(n) { stk.push(n%10); n /= 10; }}int main(){ ios::sync_with_stdio(false); string s; while(cin>>s) { int num = 0; int len = s.length(); for(int i=0;i<len;++i) { int n = s[i] - '0'; num += n; } ///获取num的位数 len = get_len(num); set_stk(num); for(int i=0;i<len;++i) { i==len-1?cout<<nm[stk.top()]<<endl:cout<<nm[stk.top()]<<" "; stk.pop(); } } return 0;}
阅读全文
0 0
- PAT1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT1005.Spell It Right
- PAT1005. Spell It Right
- pat1005 Spell It Right
- PAT1005-Spell It Right
- PAT1005 Spell It Right 大水题
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005 Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- java数据类型转换
- SCA-CNN算法笔记
- 绘制带有颜色的模型
- BZOJ1067 [SCOI2007]降雨量 RMQ+乱搞
- java HttpServlet 之 HttpServletsponse响应
- PAT1005. Spell It Right (20)
- 网易页面设计稿参考
- response和request方法
- applicationcontext.xml中sessionFactory、transactionManager等自动生成
- poj 2411 Mondriaan's Dream (状态压缩dp)
- Python之for循环
- AM335X下Linux驱动 spi 收不到消息
- 算法训练 结点选择 树形DP
- 在以(后继)线索二叉树为储存结构的二叉排序树中删除关键字为x的数据元素