pat-a 1005. Spell It Right (20)

249人阅读 评论(0) 收藏 举报
分类:

题意:

输出各个位数的数字的总和

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
char a[105];
int b[105];
char c[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{   int sum=0;
    scanf("%s",a);
    if(strlen(a)==1&&a[0]=='0')
    {
        cout<<"zero"<<endl;
        return 0;
    }
    for(int i=0;i<strlen(a);i++)
        sum+=a[i]-'0';
    int cot=0;
    while(sum!=0)
    {
        b[cot++]=sum%10;
        sum/=10;
    }
    int flag=1;
    for(int i=cot-1;i>=0;i--)
    {
        if(flag==0)
            printf(" ");
        if(flag==1)
    {
        flag=0;
    }
        printf("%s",c[b[i]]);
    }


    return 0;
}

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
char a[105];
int b[105];
char c[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{   int sum=0;
    scanf("%s",a);
    if(strlen(a)==1&&a[0]=='0')
    {
        cout<<"zero"<<endl;
        return 0;
    }
    for(int i=0;i<strlen(a);i++)
        sum+=a[i]-'0';
    int cot=0;
    while(sum!=0)
    {
        b[cot++]=sum%10;
        sum/=10;
    }
    int flag=1;
    for(int i=cot-1;i>=0;i--)
    {
        if(flag==0)
            printf(" ");
        if(flag==1)
    {
        flag=0;
    }
        printf("%s",c[b[i]]);
    }

    return 0;
}


查看评论

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

1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判...
  • artemisrj
  • artemisrj
  • 2014-02-22 14:58:00
  • 909

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 e...
  • qq_34594236
  • qq_34594236
  • 2016-07-02 20:35:43
  • 469

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 e...
  • chr1991
  • chr1991
  • 2016-06-25 06:40:15
  • 370

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

1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B...
  • wyxdexyq
  • wyxdexyq
  • 2014-10-22 17:03:14
  • 791

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

1005. Spell It Right (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B...
  • czl_chen
  • czl_chen
  • 2014-08-05 15:38:33
  • 327

PAT-A 1005. Spell It Right (20)

PAT-A 1005. Spell It Right (20)
  • Daniel960601
  • Daniel960601
  • 2017-02-22 22:35:29
  • 155

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

1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B...
  • u011662320
  • u011662320
  • 2017-07-01 16:58:37
  • 121

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 e...
  • KasimRay
  • KasimRay
  • 2018-01-16 09:58:24
  • 26

PAT-A 1005. Spell It Right

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e...
  • ww1473345713
  • ww1473345713
  • 2016-07-31 22:55:15
  • 80

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 e...
  • zjujqq
  • zjujqq
  • 2013-08-29 00:07:25
  • 489
    个人资料
    专栏达人 持之以恒
    等级:
    访问量: 11万+
    积分: 7606
    排名: 3554
    博客专栏
    acm

    文章:493篇

    阅读:83189
    openGL

    文章:15篇

    阅读:6853
    最新评论