关闭

PAT 1005. Spell It Right (20)

标签: PAT
157人阅读 评论(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
查看评论

【c++】PAT (Advanced Level) 1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a no...
  • artemisrj
  • artemisrj
  • 2014-02-22 14:58
  • 834

1005. Spell It Right (20)解题思路

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specifica...
  • chr1991
  • chr1991
  • 2016-06-25 06:40
  • 296

PAT - 甲级 - 1005. Spell It Right (20)

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specifi...
  • qq_34594236
  • qq_34594236
  • 2016-07-02 20:35
  • 408

PAT甲级真题及训练集(15)--1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
  • u011662320
  • u011662320
  • 2017-07-01 16:58
  • 104

pat 1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
  • wyh7280
  • wyh7280
  • 2015-07-17 13:23
  • 262

(PAT)1005. Spell It Right (20)

#include #include #include using namespace std; int main() { string eng[10]={"zero","one","two","three",&...
  • MrRoyLee
  • MrRoyLee
  • 2014-01-08 22:40
  • 421

PAT 1005. Spell It Right(20)

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English. Input Specifi...
  • KasimRay
  • KasimRay
  • 2018-01-16 09:58
  • 12

PAT 1005. Spell It Right (20)

1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a non-negative integer N...
  • u010069101
  • u010069101
  • 2014-02-25 18:24
  • 452

[PAT]1005. Spell It Right (20)

/************************************************************** 1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 C...
  • fnzsjt
  • fnzsjt
  • 2014-11-10 13:35
  • 789

PAT: 1005. Spell It Right (20)

1005. Spell It Right (20) PAT Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the su...
  • ZJFCLH
  • ZJFCLH
  • 2014-03-23 09:47
  • 1308
    个人资料
    • 访问:18168次
    • 积分:756
    • 等级:
    • 排名:千里之外
    • 原创:56篇
    • 转载:11篇
    • 译文:0篇
    • 评论:5条
    最新评论