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 和 ...
随机推荐
- 【CUDA 基础】4.4 核函数可达到的带宽
title: [CUDA 基础]4.4 核函数可达到的带宽 categories: - CUDA - Freshman tags: - 带宽 - 吞吐量 - 矩阵转置 toc: true date: ...
- Selenium报错:StaleElementReferenceException
一个学生在操作页面跳转时遇到一个Selenium报错, 如下图所示: StaleElementReferenceException: Message: stale element reference: ...
- 用python实现的简易记牌器的demo
实现功能很简单: 初始时 1到10 以及 jkq各 4张,大小王 共两张 只要输入相应的牌号:1到10,例如 >>1 J.K.Q :例如>>j >> ...
- Python之从继承到C3算法
在Python2.X和Python3.X有很多不同的地方,其中一个区别就是和继承有关. 在Python3.X中,一个类如果没有指明其继承哪个类的时候,其默认就是继承object类. 而在Python2 ...
- 在eclipse中查找一个类中的方法在其他哪个类中被调用了
选中你所要查看的方法名,ctrl+shift+G就可以查看所有调用过该方法的地方了.在Search视图里面可以查看得到这个样子是可以的,你也可以按Ctrl+H全文检索一下
- Navicat Premium 12 卸载和注册表的删除
卸载就不用我说了,win10也好,win7也好直接windows设置里的卸载,或者你觉得别的软件卸载的比较干净也行 不过还是不会删掉注册表,甚至文件夹都不删除, ... 这是卸载 ,在此说一下,为了安 ...
- mybatis 语句中where 后边要跟必要条件和多个选择条件处理方法
<select id="serchRelation" resultType="Relation">SELECTr.node_one as nodeO ...
- android studio最新版的安装和配置(3.1.2)
android studio最新版的安装和配置(3.1.2) 下载地址: android studio:http://www.android-studio.org/ JDK:http://www.or ...
- LC 934. Shortest Bridge
In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected grou ...
- ajax设置头信息,读取头信息
一.设置头信息 jQuery function GetDateForServiceCustomer(userId) { $.ajax({ url: 'http://*******/api/orders ...