1005. Spell It Right (20)

来源:互联网 发布:软件培训 就业 编辑:程序博客网 时间:2024/05/29 14:31
<pre name="code" class="cpp">
http://www.patest.cn/contests/pat-a-practise/1005
<div id="problemInfo" class="rfloat" style="margin: 0px; padding: 2px; border: 1px solid rgb(221, 221, 221); font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; line-height: 18px; 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-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">时间限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;">400 ms</div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">内存限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;">65536 kB</div></div><div class="limit" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">代码长度限制</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;">16000 B</div></div><div class="checker" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;"><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">判题程序</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;"><span title="纯文本对比" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;">Standard</span></div></div><div class="key" style="margin: 0px; padding: 0px 20px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline; background-color: rgb(221, 221, 221);">作者</div><div class="value" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: inherit; vertical-align: baseline;">CHEN, Yue</div></div><div id="problemContent" style="margin: 0px; padding: 0px; border: 0px; font-family: 'Droid Sans', Verdana, 'Microsoft YaHei', Tahoma, sans-serif; line-height: 18px; 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-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 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-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 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-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 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-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 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-family: inherit;font-size:undefined; font-style: inherit; font-variant: inherit; font-weight: inherit; line-height: 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-family: 'Droid Sans Mono', Consolas, 'Courier New', monospace; font-size: 1em; line-height: 1.5; vertical-align: baseline; overflow: auto;">12345
Sample Output:
one five

*/
#include<stdio.h>#include<math.h>int main(){char num[101];int sum = 0,summ,digit;int i=0,count=0;scanf("%s",num);while(num[i] != '\0')sum+=num[i++] - '0';summ = sum;while(summ/=10)count++;//sum共有count+1为2位for(count;count>=0;count--){digit = sum/(int)pow((double)10,(double)count);digit%=10;switch(digit){case 0:printf("zero");break;case 1:printf("one");break;case 2:printf("two");break;case 3:printf("three");break;case 4:printf("four");break;case 5:printf("five");break;case 6:printf("six");break;case 7:printf("seven");break;case 8:printf("eight");break;case 9:printf("nine");break;}if(count) printf(" ");}return 0;}

0 0