关闭

PAT 1005. Spell It Right (20)

标签: PAT
114人阅读 评论(0) 收藏 举报
分类:
<pre name="code" class="cpp">#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
using namespace std;
#define INF 100000000
#define min(a,b) a<b?a:b

int main()
{
    const char *str[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
         char str2[102];
         int sum=0;
         scanf("%s",str2);
         for(int i=0;str2[i]!='\0';i++)
              sum+=str2[i]-'0';
              int s=sum;
              int t=1,first=0;
              while(s)
              {
                  if(!first)
                {     t=1;
               first=1;
                    }
                    else
                  t*=10;

                  s/=10;
              }
              first=0;
              s=sum;
              int a,b;
              while(t)
              {
                  a=s/t;
                    if(!first)
                    {
                        printf("%s",str[a]);
                        first=1;
                    }
                    else
                    printf(" %s",str[a]);
                 s%=t;
                      t/=10;
              }
              printf("\n");


    return 0;
}



   
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:11869次
    • 积分:678
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:8篇
    • 译文:0篇
    • 评论:5条
    最新评论