[PAT-甲级]1005.Spell It Right
来源:互联网 发布:java通过url调用接口 编辑:程序博客网 时间:2024/06/12 20:36
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
解题报告:简单的字符串操作,题目意思是给一个数字字符串(长度最长100位),计算各位之和sum,并将sum各位从高位到低位每位用英文表示。例如:12345 各位相加等于15,15的每一位用英文表示,得到one five
代码如下:
#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;int main(){string s;int sum = 0;cin>>s;string str[10] = {"zero","one","two","three","four","five","six","seven","eight","nine",};// 计算数字字符串每位之和sumfor(int i = 0; i < s.length(); i ++)sum = sum + s[i] - '0';if(sum == 0)cout<<"zero";vector<string> vs;// 将sum的每一位英文保存到vector中while(sum){vs.push_back(str[sum%10]);sum /= 10;}reverse(vs.begin(), vs.end());vector<string>::iterator it;for(it = vs.begin(); it != vs.end(); it ++){if(it == vs.begin())cout<<*it;elsecout<<" "<<*it;}cout<<endl;return 0;}
阅读全文
0 0
- PAT - 甲级 - 1005. Spell It Right (20)
- PAT甲级.1005. Spell It Right (20)
- 【PAT甲级】1005. Spell It Right (20)
- PAT甲级1005. Spell It Right (20)
- PAT甲级1005. Spell It Right
- PAT 甲级 1005. Spell It Right
- PAT甲级 1005. Spell It Right (20)
- [PAT-甲级]1005.Spell It Right
- PAT甲级1005. Spell It Right
- PAT 甲级 1005. Spell It Right
- PAT甲级1005. Spell It Right (20)
- PAT 甲级 1005. Spell It Right (20)
- 1005. Spell It Right (20)-PAT甲级真题
- 【PAT甲级】【C++】1005. Spell It Right (20)
- PAT TEST 甲级1005. Spell It Right (20)
- PAT(甲级)1005. Spell It Right (20)
- PAT甲级练习1005. Spell It Right (20)
- PAT甲级 1005:Spell it Right
- muduo网络库源码解析 六
- java中对负数取模运算
- C#完整聊天室服务器和客户端代码实例
- SpringMVC动态获取Message
- Ubuntu 常用命令
- [PAT-甲级]1005.Spell It Right
- 外包 === _____ ? 外包 : 非外包
- C语言-给定某日期为周几求另一日期为周几
- 操作word文档书签
- 通过grep -f 比较两个文件的不同
- 怎么学好PHP
- SolidWorks v2017 SP0 Win64 1DVD
- java的静态方法继承问题
- Ketama一致性Hash算法(含Java代码)