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. UDP编程(八)

    此为网络编程系列的目录,后续会把内容补上.......

  2. Java [Leetcode 292]Nim Game

    问题描述: You are playing the following Nim Game with your friend: There is a heap of stones on the tabl ...

  3. 使用BusyBox制作嵌入式Linux根文件系统

    STEP 1:构建目录结构  创建根文件系统目录,主要包括以下目录/dev  /etc /lib  /usr  /var /proc /tmp /home /root /mnt /bin  /sbin ...

  4. (七)学习MVC之CodeFirst迁移更新数据库

    1.首先在程序包管理控制台输入:enable-migrations -force ,然后回车: 问题1: The EntityFramework package is not installed on ...

  5. 将你的Asp.NET应用程序嵌入到SharePoint

    转:http://www.cnblogs.com/Clank/archive/2007/05/21/754073.html 为什么要将Asp.net应用程序嵌入到SharePoint?这个我们不讨论! ...

  6. 关于Excel中的需求或者是用例导入到QC中遇到的问题

    Excel 中导入用例到QC时,会提示如图所示的错误信息:   解决方案: 我的电脑-->属性->高级-->性能设置-->添加QC程序 

  7. python 中 struct 用法

    下面就介绍这个模块中的几个方法. struct.pack():我的理解是,python利用 struct模块将字符(比如说 int,long ,unsized int 等)拆成 字节流(用十六进制表示 ...

  8. Spring MVC @ModelAttribute

    1.@ModelAttribute注释void返回值的方法 @Controller public class HelloModelController { @ModelAttribute public ...

  9. 你真的知道HTML吗?

    经过几次面试当中,被问及到最基础的东西,没想到回答不上来,有点蛋痛,今天特地的复习了一下!! 内容: 1.Doctype(文档类型)的作用是什么?有多少文档类型? 2.浏览器标准模式和怪异模式之间的区 ...

  10. MySQL UNION 与 UNION ALL 语法与用法

    MySQL UNION 语法 MySQL UNION 用于把来自多个 SELECT 语句的结果组合到一个结果集合中.语法为: SELECT column,... FROM table1 UNION [ ...