PAT 1005. Spell It Right (20)

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



            
阅读更多
版权声明:未经允许,可以转载 https://blog.csdn.net/Genius_J/article/details/49942935
文章标签: PAT
个人分类: PAT
上一篇PAT 1011. World Cup Betting (20)
下一篇PAT 1019. General Palindromic Number (20)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭