• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
2014>
博客园    首页    新随笔    联系   管理    订阅  订阅
pat1005

1005. Spell It Right (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:
12345
Sample Output:
one five

提交代码

#include<iostream>
#include<vector>
#include<cstdio>
#include<string.h>
#include<string>
using namespace std;
string b[100];
int main()
{
    b[1]="one",b[2]="two",b[3]="three",b[4]="four",b[5]="five",b[6]="six",b[7]="seven",b[8]="eight",b[9]="nine",b[0]="zero";
    char a[1000];
    gets(a);
    int t=strlen(a);
    int sum=0;

    for(int i=0;i<t;i++)
    {
        sum=sum+(a[i]-'0');

    }
   int c[10000];
    int i=0;
   while(sum>0)
   {
       c[i]=sum%10;
       sum=sum/10;
       i++;
   }
   i--;
   for(;i>0;i--)
   {
      cout<<b[c[i]]<<" ";
   }
   cout<<b[c[0]]<<endl;
    return 0;
}

 

posted on 2017-11-07 10:34  2014>  阅读(190)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3