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

简单的模拟类型题,没什么好说的。

代码

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 int main()
 5 {
 6     char str[];
 7     char* const_str[] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
 8     while(gets(str)){
 9         int n = strlen(str);
         int i = ;
         int sum = ;
         for (;i<n;++i){
             sum = sum + str[i] - '';
         }
         sprintf(str,"%d",sum);
         n = strlen(str);
         printf("%s",const_str[str[]-'']);
         for(i=;i<n;++i){
             printf(" %s",const_str[str[i]-'']);
         }
         printf("\n");
     }
     return ;
 }

PAT 1005的更多相关文章

  1. PAT——1005. 继续(3n+1)猜想

    pat原题目:https://www.patest.cn/contests/pat-b-practise/1005 原题目: 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况 ...

  2. PAT 1005 Spell It Right

    1005 Spell It Right (20 分)   Given a non-negative integer N, your task is to compute the sum of all ...

  3. PAT 1005 继续(3n+1)猜想 (25)(代码)

    1005 继续(3n+1)猜想 (25)(25 分) 卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下 ...

  4. PAT 1005. 继续(3n+1)猜想 (25) JAVA

    当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候,我们需要计算3.5.8.4.2.1,则当我们对n=5.8.4.2进行验证的时候,就可以直接 ...

  5. PAT 1005. 继续(3n+1)猜想 (25)

    卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候, ...

  6. PAT——1005. 继续(3n+1)猜想 (25)

    卡拉兹(Callatz)猜想已经在1001中给出了描述.在这个题目里,情况稍微有些复杂. 当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数.例如对n=3进行验证的时候, ...

  7. PAT 1005 继续(3n+1)猜想

    https://pintia.cn/problem-sets/994805260223102976/problems/994805320306507776 卡拉兹(Callatz)猜想已经在1001中 ...

  8. PAT 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 ...

  9. PAT 乙级 1005

    题目 题目地址:PAT 乙级 1005 题解 本题主要就在于将一个数的一系列计算结果不重复地存储起来并便于检索,考虑到STL中的集合有相似的特性,使用set可以有效地简化代码和运算. 过程如下: (初 ...

随机推荐

  1. U-boot mkimage指定Linux内核地址时的两种方式

    http://blog.csdn.net/embededswordman/article/details/6704197 uImage的制作是使用的u-boot工具mkimage,build完u-bo ...

  2. C# 中的结构类型(struct)

    原文 C# 中的结构类型(struct) 简介 有时候,类中只包含极少的数据,因为管理堆而造成的开销显得极不合算.这种情况下,更好的做法是使用结构(struct)类型.由于 struct 是值类型,是 ...

  3. 【原创】Linux下使用SecureCRT的方法:破解&编码

    1.下载SecureCRT软件 ubuntu64位:http://download.csdn.net/detail/cobps/7941145 ubuntu32位:http://download.cs ...

  4. mac usb转串口 连接树莓PI

    USB 转串口是淘宝买的 http://item.taobao.com/item.htm?spm=a1z09.2.9.50.YOJBwG&id=38963495468&_u=4m1dr ...

  5. 多线程与网络之JSON和XML数据的解析

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  6. [原][Android]All WebView methods must be called on the same thread.

    问题 webView调用JS出错. class TestJS {         ......         public TestJS(){         }                   ...

  7. 【暑假】[实用数据结构] AC自动机

    Aho-Corasick自动机  算法: <功能> AC自动机用于解决文本一个而模板有多个的问题. AC自动机可以成功将多模板匹配,匹配意味着算法可以找到每一个模板在文本中出现的位置. & ...

  8. SQL注入攻击及防范

    一.什么是SQL注入1.SQL注入的定义     SQL注入(SQL Injection) 利用了程序中的SQL的漏洞,进行攻击的方法. 2.SQL注入举例  1)利用SQL语法错误获取数据库表的结构 ...

  9. HTML5学习之FileReader接口

    http://blog.csdn.net/zk437092645/article/details/8745647 用来把文件读入内存,并且读取文件中的数据.FileReader接口提供了一个异步API ...

  10. 集群搭建必备:虚拟机之一实现Host-only方式上网

    Host-only模式实现联网得考虑如下配置过程: 1. 安装VMware-Workstation,安装虚拟机Linux(centos.ubuntu等)完毕: 2.设置虚拟机上网方式是Host-onl ...