Fork me on GitHub

PAT1005

水题,和中文没啥区别不说了。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>

using namespace std;

char maps[10][10]={
    {"zero"},{"one"},{"two"},{"three"},{"four"},{"five"},{"six"},{"seven"},{"eight"},{"nine"}
};

int main()
{
    char ch;
    int sum=0;
    while ((ch = getchar()) != '\n')
    {
        sum += (ch -'0');
    }
    int a[1000],i=0;
    while (sum > 10)
    {
        a[i] = sum%10;
        sum /= 10;
        i++;
    }
    a[i] = sum;
    while (i>0)
    {
        cout<<maps[a[i]]<<" ";
        i--;
    }
    cout<<maps[a[0]]<<endl;
    return 0;  
}
posted @ 2016-07-15 22:09  LinkinStar  阅读(196)  评论(0编辑  收藏  举报