PAT A1005 Spell It Right (20)
书中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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- pat1005. Spell It Right (20)
1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT 乙级 1007. 素数对猜想 (20) c++ 筛选法求素数
PAT 乙级 1007. 素数对猜想 (20) c++ 筛选法求素数 让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对于n>1有 dn 是偶数 ...
- 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 ...
- PAT乙级:1088 三人行 (20分)
PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...
- PAT乙级:1064 朋友数 (20分)
PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...
随机推荐
- 什么是nProtect?
nProtect是设计用于保护个人电脑终端不被病毒和黑客程序感染的新概念的基于网络的反黑客和反病毒的工具. 他帮助确保所有输入个人电脑终端的信息在网络上不落入黑客手中. 在最终用户在执行电子贸易时,可 ...
- Django-静态文件导入/url命名及反向解析
一.静态文件导入 js.css.img等都叫做静态文件,那么关于django中静态文件的配置,我们就需要在settings配置文件里面写上这写内容: # STATIC_URL = '/xxx/' #别 ...
- D. Shortest Cycle(floyd最小环)
D. Shortest Cycle time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- MyBatis动态Sql 的使用
Mapper.xml提示: 1:mapper包中新建一个文件:mybatis-3-mapper.dtd 2:在web app libraries/mybatis.jar/org.apache.ibat ...
- zookeeper系列(九)zookeeper的会话详解
作者:leesf 掌控之中,才会成功:掌控之外,注定失败. 出处:http://www.cnblogs.com/leesf456/p/6103870.html尊重原创,大家共同学习: 一.前言 ...
- Linux设备驱动程序 之 read和write
read和write原型 read和write方法完成的任务是相似的,亦即,拷贝数据到应用程序空间,或者反过来从应用程序空间拷贝数据:因此,它们的原型很相似,如下: ssize_t (*read) ( ...
- C++ STL——string和vector
目录 一 STL基本概念 二 string容器 三 vector容器 3.1 vector动态增长原理 3.2 vector构造函数 3.3 vector常用赋值操作 3.4 vector大小操作 3 ...
- 06 MySQL之索引
01-索引 1.索引是对数据库表中一列或多列的值进行排序的一种数据结构,使用索引可提高数据库中特定数据的查询速度. 2.索引是一个单独的.存储在磁盘上的数据库结构,包含对数据表里所有记录的引用指针. ...
- pytest+allure展示环境信息
allure展示环境信息 要将信息添加到Environment小部件,只需在生成报告之前在目录中创建environment.properties(或environment.xml)文件allure-r ...
- Node安装配置
下载安装nodejs后进行如下配置: 修改模块安装位置和缓存位置在要存放的位置手动新建全局目录node_global在要存放的位置手动新建缓存目录node_cache执行如下命令:npm config ...