美文网首页PTA甲级
Advanced 1005 Spell It Right(20

Advanced 1005 Spell It Right(20

作者: zilla | 来源:发表于2018-12-31 16:31 被阅读0次

PAT题目链接

#include <stdio.h>
#include <string.h>
const int N=105;
const char words[10][10]=
        {"zero","one","two","three","four",
         "five","six","seven","eight","nine"};
int main() {
    char str[N];
    while (scanf("%s", str) != EOF) {
        int len=strlen(str),ans=0;
        for(int i=0;i<len;i++){
            ans+=str[i]-'0';
        }
        if(ans>=100){
            printf("%s %s %s\n",words[ans/100],words[ans/10%10],words[ans%10]);
        } else if(ans>=10){
            printf("%s %s\n",words[ans/10],words[ans%10]);
        } else{
            printf("%s\n",words[ans]);
        }
    }
    return 0;
}

相关文章

网友评论

    本文标题:Advanced 1005 Spell It Right(20

    本文链接:https://www.haomeiwen.com/subject/hpcwlqtx.html