PAT 1005 Spell It Right 水题

//1005
char a[105];
char* num[] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
stack<char*> out;
int main(){

    while(scanf("%s",a)!=EOF){
        int sum=0;
        for(int i=0;i<strlen(a);i++){
            sum+=a[i]-'0';
        }
        if(sum==0) out.push(num[sum]);
        while(sum){
            out.push(num[sum%10]);
            sum/=10;
        }
        while(!out.empty()){
            printf("%s",out.top());
            out.pop();
            if(!out.empty()) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

PAT 1005 Spell It Right 水题PAT 1005 Spell It Right 水题 wizardOfCode 发布了66 篇原创文章 · 获赞 4 · 访问量 4120 私信 关注
上一篇:LeetCode 301. Remove Invalid Parentheses(DP)


下一篇:PAT乙级 1005 继续(3n+1)猜想