首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

PAT Advanced 1005

1005. Spell It Right (20)

时间限制 400 ms

内存限制 32000 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:

代码语言:javascript
复制
12345

Sample Output:

代码语言:javascript
复制
one five
代码语言:javascript
复制
代码语言:javascript
复制
#include<stdio.h>
char a[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};
/*递归的从左至右输出各个位*/
void b(int sum,int count)
{
	count++;
	if(sum/10 !=0 )
		b(sum/10,count);
	if(count==1)
		printf("%s",a[sum%10]);
	else
		printf("%s ",a[sum%10]);
}

int main()
{
	char n[102];//10的100次方最大存储空间
	int i=0,sum=0,r=1;
	scanf("%s",n);
	while(n[i]!='\0')
		sum += n[i++]-48 ;
	b(sum,0);
	return 0;
}
代码语言:javascript
复制
代码语言:javascript
复制
下一篇
举报
领券