PAT: 1005. Spell It Right (20)
2014-03-23 09:47
435 查看
1005. Spell It Right (20)
时间限制400 ms内存限制32000 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
AC代码:
//运用map来实现数字和英文的转换#include<stdio.h>#include<iostream>#include<string.h>#include<string>#include<map>using namespace std;#define N 100 //此题的测试数据较少,定义100足够了char num;int main(){//freopen("in.txt","r",stdin);map<int,string> ma;ma[0] = "zero"; ma[1] = "one";ma[2] = "two"; ma[3] = "three";ma[4] = "four"; ma[5] = "five";ma[6] = "six"; ma[7] = "seven";ma[8] = "eight"; ma[9] = "nine";gets(num);int len = strlen(num);int sum=0;for(int i=0; i<len; i++) {sum += num[i]-'0';}int k = N;int flag=0; //实现不输出前导0while(k!=1) {int a = sum/k;sum %= k;if(a!=0 && flag==0) {flag = 1;}if(flag == 1) {cout<<ma[a]<<" ";}k /= 10;}cout<<ma[sum]<<endl;return 0;}[/code]
相关文章推荐
- PAT-Java-1005-Spell It Right (20)
- (PAT)1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT 甲级 1005. Spell It Right (20) 【字符串】
- PAT (Advanced Level) 1005. Spell It Right (20) string转int,哈希
- PAT (Advanced Level) 1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- PAT (Advanced Level) Practise - 1005. Spell It Right (20)
- PAT甲级.1005. Spell It Right (20)
- PAT甲级1005. Spell It Right (20)
- PAT1005. Spell It Right (20)
- 【PAT】【Advanced Level】1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- PAT1005. Spell It Right (20)
- pat 1005. Spell It Right (20)
- PAT-1005 Spell It Right (20)
- PAT(Advanced Level)1005. Spell It Right (20) 栈 int转string
- PAT---1005. Spell It Right (20)