1005. Spell It Right (20)
2016-07-01 15:00
302 查看
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:
Sample Output:
给定一串数字,求各位数加起来的和,将求得的和每一位“读”出来。要注意读的顺序。
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
string spell[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{
string s;
cin>>s;
int n=0;
for(int i=0;i<s.size();i++)
{
n+=s[i]-'0';
}
if(n==0)
{
cout<<"zero";
return 0;
}
int m=0;
vector<int>res;
while(n>0)
{
m=n%10;
n=n/10;
res.push_back(m);
}
int len=res.size();
cout<<spell[res[len-1]];
for(int i=len-2;i>=0;i--)
{
cout<<" "<<spell[res[i]];
}
}
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 <vector>
#include <cstring>
using namespace std;
string spell[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{
string s;
cin>>s;
int n=0;
for(int i=0;i<s.size();i++)
{
n+=s[i]-'0';
}
if(n==0)
{
cout<<"zero";
return 0;
}
int m=0;
vector<int>res;
while(n>0)
{
m=n%10;
n=n/10;
res.push_back(m);
}
int len=res.size();
cout<<spell[res[len-1]];
for(int i=len-2;i>=0;i--)
{
cout<<" "<<spell[res[i]];
}
}
相关文章推荐
- 微软Word 2007数学插件 Microsoft Math 提供下载
- 关于C# Math 处理奇进偶不进的实现代码
- JavaScript Math 对象常用方法总结
- JavaScript中的Math.SQRT1_2属性使用简介
- JavaScript Math.ceil() 函数使用介绍
- 与Math.pow 相反的函数使用介绍
- JavaScript中使用指数方法Math.exp()的简介
- JavaScript使用Math.Min返回两个数中较小数的方法
- Ajax获取页面被缓存的解决方法
- JavaScript高级程序设计 阅读笔记(十二) js内置对象Math
- JavaScript中Math对象使用说明
- javascript对象之内置对象Math使用方法
- 基于java math API 的详细解释说明
- 简介JavaScript中用于处理正切的Math.tan()方法
- 浅谈JavaScript中的Math.atan()方法的使用
- PHP内置的Math函数效率测试
- 在JavaScript中使用对数Math.log()方法的教程
- JavaScript中用于四舍五入的Math.round()方法讲解
- Javascript之Math对象详解
- 简介JavaScript中Math.LOG10E属性的使用