PAT Advanced 1005
来源:互联网 发布:影子去除算法 编辑:程序博客网 时间:2024/06/05 15:15
题目如下:
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
#include<iostream>#include<string>#include<sstream>#include<vector>using namespace std;int sumdigits(string data);template<class out, class in>out convert(in a);int main(){ string data; string digit[] = {"zero","one","two","three","four","five","six","seven","eight","nine"}; string temp; while(cin>>data) { temp = convert<string>(sumdigits(data)); for(int i = 0; i < temp.length(); i++) { cout<<digit[convert<int>(temp[i])]; if (i != temp.length() - 1) cout<<" "; } cout<<endl; } return 0;}int sumdigits(string data){ if ("" == data) return 0; int sum = 0; sum += convert<int>(data[data.length()-1]); sum += sumdigits(data.substr(0, data.length() - 1)); return sum; }template<class out, class in>out convert(in a){ stringstream temp; temp<<a; out b; temp>>b; return b;}
0 0
- PAT Advanced 1005
- PAT Advanced 1005
- PAT (Advanced Level) Practise 1005
- pat:1005<advanced> <字符转换为单词>
- PAT Advanced Level 1005:Spell It Right
- PAT Advanced 1065
- PAT Advanced 1001
- PAT Advanced 1043
- PAT Advanced 1042
- PAT Advanced 1067
- PAT Advanced 1066
- pat advanced 1044
- pat advanced 1042
- pat advanced 1043
- pat advanced 1032
- pat:1002(Advanced)
- pat advanced 1050
- pat advanced 1051
- poj 2253 最短路
- tomcat详细解析
- poj 1201
- java网络编程
- C++ map学习1
- PAT Advanced 1005
- VIM常用命令
- 【BZOJ 1030】 [JSOI2007]文本生成器
- hadoop权威指南,天气数据文件自动下载下载
- Interleaving String|leetcode题解
- subsys_initcall宏定义的一个例子,acpi/bus.c里面。
- 低功耗蓝牙4.0BLE编程-nrf51822开发(8)-GATT
- ZOJ Problem Set - 2417 Lowest Bit
- 《iOS极光推送步骤》