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 <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
using namespace std;
const int maxn = 100100;
#define LL long long
int main()
{
char s[111];
scanf("%s",s);
int now=0;
int len=strlen(s);
for(int i=0;i<len;i++){
now+=s[i]-'0';
}
if(now==0){
printf("zero\n");
return 0;
}
int num[111];
int cnt=0;
while(now){
num[++cnt]=now%10;
now/=10;
}
map<int,string> mp;
mp[0]="zero";
mp[1]="one";
mp[2]="two";
mp[3]="three";
mp[4]="four";
mp[5]="five";
mp[6]="six";
mp[7]="seven";
mp[8]="eight";
mp[9]="nine";
for(int i=cnt;i>=1;i--){
if(i!=cnt) printf(" ");
cout<<mp[num[i]];
}
}
本文介绍了一个编程问题,即给定一个非负整数N,计算其所有位数的和,并将该和的每一位数字用英文单词表示出来。输入为一个大整数,输出则是该整数各位相加后的和的每一位数字的英文单词形式。
941

被折叠的 条评论
为什么被折叠?



