PAT 1005. Spell It Right (注意考虑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;
}

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

时间: 2024-07-29 00:18:07

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

PAT 1005. Spell It Right

PAT 1005. Spell It Right (20) 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 li

PAT 1005. Spell It Right (20)

1005. Spell It Right (20) 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 w

PAT甲级1005 Spell It Right

题目:PAT甲级 1005 题解:水题.看到题目的第一时间就在想一位一位的mod,最后一加一转换就完事了.结果看到了N最大为10的100的次方,吓得我赶紧放弃这个想法... 发现碰到这种情况用字符串十分好用,这道题应该考察的就是这一点.大致思路就是把数字的每一位放到字符串中,然后通过ASCII码得到每一位的相加结果num,然后把num一位一位的放到stack中,使用stack是因为它先进先出的特性,最后输出就行了. 代码: 1 #include<cstdio> 2 #include<qu

1005. Spell It Right (20) -PAT

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 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: E

1005. Spell It Right (20)——PAT (Advanced Level) Practise

题目信息: 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 Specificat

PAT 1005

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 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: E

1005. Spell It Right

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 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: E

1005 Spell It Right (20)(20 分)

1005 Spell It Right (20)(20 分) 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 l

PAT A1005 Spell It Right

PAT A1005 Spell It Right 题目描述: 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 l