书中AC代码

#include <cstdio>
#include <cstring>
#include <iostream>
char num[10][10] = { //数字与单词的对应
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
};
char s[111]; //初始化字符串
int digit[10]; using namespace std;
int main() {
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
cin.getline(s, 111);
int len = strlen(s);
int sum = 0, numLen = 0; //sum为s的数位之和,numLen计量sum的长度
for(int i = 0; i < len; i++) {
sum += (s[i] - '0'); //累加s的数位,得到sum
}
if(sum == 0) { //如果sum为0,特判输出num[0]
printf("%s", num[0]);
} else { // 如果sum不为零
while(sum != 0) { //将sum存到digit数组中
digit[numLen++] = sum % 10;
sum /= 10;
}
for(int i = numLen - 1; i >= 0; i--) { //从高位到低位输出digit数组
printf("%s", num[digit[i]]);
if(i != 0) printf(" "); //最后一个单词之后不输出空格
}
}
return 0;
}

PAT A1005 Spell It Right (20)的更多相关文章

  1. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...

  2. PAT 甲级 1005 Spell It Right (20)(代码)

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

  3. PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  4. PTA 1005 Spell It Right (20)(20 分)水题

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

  5. pat1005. Spell It Right (20)

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  6. PAT 乙级 1007. 素数对猜想 (20) c++ 筛选法求素数

    PAT 乙级 1007. 素数对猜想 (20) c++ 筛选法求素数 让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对于n>1有 dn 是偶数 ...

  7. 1005 Spell It Right (20分)

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

  8. PAT乙级:1088 三人行 (20分)

    PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...

  9. PAT乙级:1064 朋友数 (20分)

    PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...

随机推荐

  1. JavaWeb_(Spring框架)在Struts+Hibernate框架中引入Spring框架

    spring的功能:简单来说就是帮我们new对象,什么时候new对象好,什么时候销毁对象. 在MySQL中添加spring数据库,添加user表,并添加一条用户数据 使用struts + hibern ...

  2. iOS 8 - Can't Install Enterprise App

    http://stackoverflow.com/questions/25733299/ios-8-cant-install-enterprise-app 版权声明:本文为博主原创文章,未经博主允许不 ...

  3. java.util.Date和java.sql.Date的区别和相互转化 (转)

    java.util.Date和java.sql.Date的区别及应用   java.util.Date 就是在除了SQL语句的情况下面使用 java.sql.Date 是针对SQL语句使用的,它只包含 ...

  4. LeetCode 44. 通配符匹配(Wildcard Matching)

    题目描述 给定一个字符串 (s) 和一个字符模式 (p) ,实现一个支持 '?' 和 '*' 的通配符匹配. '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个字符串完 ...

  5. antd源码分析之——标签页(tabs 2.Tabs关键组件功能实现)

    由于ant Tabs组件结构较复杂,共分三部分叙述,本文为目录中第二部分(高亮) 目录 一.组件结构 antd代码结构 rc-ant代码结构 1.组件树状结构 2.Context使用说明 3.rc-t ...

  6. springboot使用RestTemplate以post方式发送json字符串参数(以向钉钉机器人发送消息为例)

    使用springboot之前,我们发送http消息是这么实现的 我们用了一个过时的类,虽然感觉有些不爽,但是出于一些原因,一直也没有做处理,最近公司项目框架改为了springboot,springbo ...

  7. Flutter移动电商实战 --(4)打通底部导航栏

    关于界面切换以及底栏的实现可参考之前写的一篇文章:Flutter实 ViewPager.bottomNavigationBar界面切换 1.新建4个基本dart文件 在pages目录下,我们新建下面四 ...

  8. CentOS 7 应用

    为方便以下CentOS7简称C7,CentOS6简称C6 优化 1.安装常用功能 yum -y install bash-completion lrzsz telnet tree vim wget n ...

  9. 人才-T型人才:百科

    ylbtech-人才-T型人才:百科 T型人才是指按知识结构区分出来的一种新型人才类型.用字母“T”来表示他们的知识结构特点.“—”表示有广博的知识面,“|”表示知识的深度.两者的结合,既有较深的专业 ...

  10. HttpClient提交数据

    用代码模拟浏览器的行为 * 轻量级的开源的框架 * Android在6.0 23 以后移除了httpclient ,所以开发中用的少了 * 编写步骤: 1. 打开浏览器 2. 输入网址 3. 敲回车 ...