PAT甲级 1005.Spell It Right(20) 题目翻译与答案

题目来源自PAT网站  https://www.patest.cn/

题目描述:

1005. Spell It Right (20)

Given anon-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.

InputSpecification:

Each input filecontains one test case. Each case occupies one line which contains an N (<=10100).

OutputSpecification:

For each test case,output in one line the digits of the sum in English words. There must be onespace between two consecutive words, but no extra space at the end of a line.

SampleInput:

12345

SampleOutput:

one five

时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

 

题目翻译:

1005.正确拼写它

给一个非负整数N,你的任务是计算N的所有位数的和,然后用英语输出和的每位。

 

输入说明:

每个输入文件包含一个测试实例。每个实例有一行,一行中含有一个数字N(<= 10100)。

 

输出说明:

对于每个测试用例,在一行内用英语单词输出和的每位。在两个连续的单词之间必须有一个空格,但是在一行的末尾不能有多余的空格。

 

样例输入:

12345

 

样例输出:

one five

 

答案代码:

#include
char *english[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char str[100];
char digit[6]="\0";

int main()
{
	int sum=0,tsum;
	int i;
	scanf("%s",str);
	for(i=0;str[i]!=0;i++)
		sum+=str[i]-'0';
	tsum=sum;
	i=0;
	while(tsum>0)
	{
		digit[i]=tsum%10;
		tsum=tsum/10;
		i++;
	}
	while(--i>0)
	{
		printf("%s ",english[digit[i]]);
	}
	printf("%s\n",english[digit[i]]);
	return 0;
}



你可能感兴趣的:(PAT甲级)