码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 1005. Spell It Right (注意考虑0的情况)

时间:2015-07-21 12:48:23      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

代码:

#include<cstdio>
#include<cstring>
using namespace std;

char s[10][20];

int main()
{
    strcpy(s[0],"zero");//对字符数组赋值
    strcpy(s[1],"one");
    strcpy(s[2],"two");
    strcpy(s[3],"three");
    strcpy(s[4],"four");
    strcpy(s[5],"five");
    strcpy(s[6],"six");
    strcpy(s[7],"seven");
    strcpy(s[8],"eight");
    strcpy(s[9],"nine");
    char ss[105];
    while(scanf("%s",ss)==1)
    {
        int ans=0;
        int len=strlen(ss);
        if(strcmp(ss,"0")==0)
        {
            printf("zero\n");
            continue;
        }
        for(int i=0;i<len;i++)
        {
            ans+=(ss[i]-'0');
        }
        int a[105];
        int k=0;
        while(ans)
        {
            int r=ans%10;
            a[k]=r;
            k++;
            ans=ans/10;
        }
        for(int i=k-1;i>=0;i--)
        {
            if(i==0)
                printf("%s\n",s[a[i]]);
            else
                printf("%s ",s[a[i]]);
        }
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

PAT 1005. Spell It Right (注意考虑0的情况)

标签:

原文地址:http://blog.csdn.net/xky1306102chenhong/article/details/46983977

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!