PAT1005. Spell It Right (20)

<h1 style="margin: 0px 0px 0.5em; padding: 0px; border: 0px; font-weight: normal; font-stretch: inherit; font-size: 3em; line-height: 1em; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(17, 17, 17); background-color: rgb(250, 250, 250);">1005. Spell It Right (20)</h1><div id="problemInfo" class="rfloat" style="margin: 0px; padding: 2px; border: 1px solid rgb(221, 221, 221); font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; float: right; text-align: center; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">时间限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">400 ms
</div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">内存限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">65536 kB
</div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">代码长度限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">16000 B
</div></div><div class="checker" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">判题程序</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><span title="纯文本对比" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">Standard</span></div></div><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">作者</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">CHEN, Yue
</div></div><div id="problemContent" style="margin: 0px; padding: 0px; border: 0px; font-stretch: inherit; line-height: 18px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; vertical-align: baseline; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);"><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">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.</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><strong>Input Specification:</strong></p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">Each input file contains one test case. Each case occupies one line which contains an N (<= 10<sup style="line-height: 0;">100</sup>).</p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;"><strong>Output Specification:</strong></p><p style="margin-top: 0px; margin-bottom: 1.5em; padding-top: 0px; padding-bottom: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit;font-size:undefined; line-height: inherit; font-family: inherit; vertical-align: baseline;">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.</p><strong>Sample Input:</strong><pre style="margin-top: 1.5em; margin-bottom: 1.5em; padding: 0px; border: 0px; font-stretch: normal; font-size: 1em; line-height: 1.5; font-family: 'Droid Sans Mono', Consolas, 'Courier New', monospace; vertical-align: baseline; overflow: auto;">12345
Sample Output:
one five
 
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	char s[110];
	memset(s,0,sizeof(s));
	gets(s);
	int len=strlen(s);
	int sum=0;
	for(int i=0;i<len;i++)
	{
		sum= sum+(s[i]-'0');
	}
	int ans[10]={0};	
	int j=0;
	while(sum)
	{
      ans[j] = sum%10;
	  sum/=10;
	  j++;
	}
	j--;
	for(;j>0;j--)
	{
		if(ans[j]==0)
		    printf("zero ");
		else if(ans[j]==1)
		    printf("one ");
		else if(ans[j]==2)
		    printf("two ");
		else if(ans[j]==3)
		    printf("three ");
		else if(ans[j]==4)
		    printf("four ");
		else if(ans[j]==5)
		    printf("five ");
		else if(ans[j]==6)
		    printf("six ");
		else if(ans[j]==7)
		    printf("seven ");
		else if(ans[j]==8)
		    printf("eight ");
		else
			printf("nine ");
	}
	j=0;
	   if(ans[j]==0)
		    printf("zero\n");
		else if(ans[j]==1)
		    printf("one\n");
		else if(ans[j]==2)
		    printf("two\n");
		else if(ans[j]==3)
		    printf("three\n");
		else if(ans[j]==4)
		    printf("four\n");
		else if(ans[j]==5)
		    printf("five\n");
		else if(ans[j]==6)
		    printf("six\n");
		else if(ans[j]==7)
		    printf("seven\n");
		else if(ans[j]==8)
		    printf("eight\n");
		else
			printf("nine\n");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值