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

醉酒当歌 提交于 2020-02-20 07:35:03

简单题。

#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;
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!