1005. Spell It Right (20)
来源:互联网 发布:数据库有5个事务 编辑:程序博客网 时间:2024/06/12 01:39
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
#include <iostream>#include <string>using namespace std;string intConvertString(int n) { switch(n) { case 1: return "one"; break; case 2: return "two"; break; case 3: return "three"; break; case 4: return "four"; break; case 5: return "five"; break; case 6: return "six"; break; case 7: return "seven"; break; case 8: return "eight"; break; case 9: return "nine"; break; case 0: return "zero"; break; }}int main() { string str; int i, sum; while(cin>>str) { sum = 0; for(i=0; i<str.length(); i++) { sum += str[i] - '0'; } int gewei = sum % 10; sum /= 10; int shiwei = sum % 10; sum /= 10; int baiwei = sum % 10; if(baiwei == 0) { if(shiwei == 0) { cout<<intConvertString(gewei)<<endl; }else { cout<<intConvertString(shiwei)<<" "; cout<<intConvertString(gewei)<<endl; } }else { cout<<intConvertString(baiwei)<<" "; cout<<intConvertString(shiwei)<<" "; cout<<intConvertString(gewei)<<endl; } } return 0;}
0 0
- 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)
- 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)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1003. Emergency (25)
- 1004. Counting Leaves (30)
- 杭电---2053 Switch Game
- LeetCode[172]Factorial Trailing Zeroes
- poj1466
- 1005. Spell It Right (20)
- 学分平均绩计算方法
- Struts2学习笔记一
- hasOwnProperty()与for in的区别
- 静态变量中的两种两种取出方式self和对象取值
- 引用导出类后类初始化顺序
- cf Round #276 (Div. 2) D. Maximum Value
- OC程序设计中的单例模式
- 一种新排序算法的探讨