1005. Spell It Right (20)
2016-04-06 21:27
417 查看
1005. Spell It Right (20)
时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven 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
#include<iostream>#include<vector>#include<map>#include<string>using namespace std;int main(){map<int,string> map1;map1[0]="zero";map1[1]="one";map1[2]="two";map1[3]="three";map1[4]="four";map1[5]="five";map1[6]="six";map1[7]="seven";map1[8]="eight";map1[9]="nine";int sum=0,temp=0;vector<int> vec;vector<int>::iterator iter;string str;cin>>str;for(int i=0;i<str.length();i++){sum=sum+(str[i]-'0');}temp=sum;if(temp==0)//考虑完整,即为零的情况cout<<map1[0];while(temp){vec.push_back(temp%10);temp=temp/10;}for(int i=vec.size()-1;i>=0;i--){cout<<map1[vec[i]];if(i!=0)cout<<" ";}}
相关文章推荐
- windows8.1/10 添加网络打印机的方法
- 数位DP (51nod)
- Linux内核实验作业六
- ABP源码分析二十三:Authorization
- 练习题之生产者消费者模型
- 软考中高项学员:2016年4月4日作业
- 机房收费系统之退卡
- QLineEdit类
- 分类-3-生成学习-3-朴素贝叶斯模型、laplace平滑、多元伯努利事件模型、多项式事件模型
- C++ 二维动态数组创建及越界问题
- quick组件模块的使用以及简单案例
- Android的桌面小图标Widget的学习
- scrollWidth,clientWidth,offsetWidth的区别
- QXmlStreamReader与QXmlStreamWriter的使用
- 常量指针与指针常量
- elseif.php else if($i>3)
- Ubuntu设置环境变量
- 数字在排序数组中出现的次数
- 小小ARC造福无数码农
- 如何实现翻转一串二进制代码: