PTA甲级

Advanced 1005 Spell It Right(20

2018-12-31  本文已影响0人  zilla

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;
}
上一篇 下一篇

猜你喜欢

热点阅读