首页 > 学院 > 开发设计 > 正文

PAT A1005. Spell It Right (20)

2019-11-11 01:30:15
字体:
来源:转载
供稿:网友

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 <cstdio>#include <algorithm>#include <cmath>#include <cstring>#define Max 100001using namespace std;int main(){	char N[11][11]={"zero","one","two","three","four","five","six","seven","eight","nine"};	char n[111];	int sum=0,m[111],k=0;	scanf("%s",n);	for(int i=0;i<strlen(n);i++)	{		sum+=n[i]-'0';	}	if(sum==0) PRintf("zero/n");	else {		while(sum>0)		{			m[k++]=sum%10;			sum/=10;		}		for(int i=k-1;i>=0;i--)		{			printf("%s",N[m[i]]);			if(i==0) printf("/n");			else printf(" ");		}	}	system("pause");	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表