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

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

时间:2016-05-15 21:40:35      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

简单题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;

const int maxn=100+10;
char s[maxn];
int tmp[maxn],tot;
char ans[15][7]={
    "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
};

int main()
{
    scanf("%s",s);
    int num=0; for(int i=0;s[i];i++) num=num+s[i]-0;
    if(num==0)
    {
        printf("zero\n");
    }
    else{
        tot=0; while(num) tmp[tot++]=num%10,num=num/10;
        for(int i=tot-1;i>=0;i--)
        {
            printf("%s",ans[tmp[i]]);
            if(i>0) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

 

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

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/5495993.html

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