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 和 ...
随机推荐
- 【线性代数】1-1:线性组合(Linear Combinations)
title: [线性代数]1-1:线性组合(Linear Combinations) toc: true categories: Mathematic Linear Algebra date: 201 ...
- Nginx-HTTP之ngx_http_top_header_filter
1. ngx_http_top_header_filter 该链表主要是用于构造响应消息的消息报头. ngx_http_top_header_filter 单链表有如下模块插入了操作: ngx_htt ...
- Linux Centos安装宝塔面板教程
材料:阿里云服务器远程ip地址和购买服务的账号和密码 版本Centos 6.9版本 用Xshell远程登录安装宝塔 Xshell的界面是这样的,如图 点击左上角新建回话可以创建一个新的SSH连接,如图 ...
- Android跨进程通信AIDL服务
服务(Service)是android系统中非常重要的组件.Service可以脱离应用程序运行.也就是说,应用程序只起到一个启动Service的作用.一但Service被启动,就算应用程序关闭,Ser ...
- 在DELPHI中动态创建控件以及控件的事件
在DELPHI中我们经常要动态的创建控件以及控件的事件.例如,我们可能想根据程序需要动态的创建一些Tshape组件来创建某个图形,并使得在鼠标移动上去之后可以完成某些操作.这一般需要需要三步: 生成一 ...
- React Native小知识点记录
1>查看 RN 的所有历史版本: npm view react-native versions -json 2>查看 RN 的当前版本: npm view react-native ver ...
- vs把asp.net旧的项目名称全部修改
1 先打开项目,把名称全部替换掉,然后把解决方案,程序集名称全部替换掉. 2 重新生成,清理,关闭项目. 3 把.sln文件用文本编辑器打开,替换里面的名称,然后把文件夹名称都修改好.d 4.打开项目 ...
- babylon 初试
出于对web端3D技术的对比,以及WebGL的发展现状和WebGPU的发展前景,我觉得有必要涉猎一下babylon.js了. 可以参考一下下列文章: 1⃣️下一代web端图形接口现状与前景:https ...
- SecurityLibrary
using System; using System.IO; using System.Linq; using System.Security.Cryptography; using System.T ...
- Django之权限(起步)
一. 权限概述 1. 认识权限 为什么要有权限? 因为权限让不同的用户拥有不同的功能. 权限可以对功能进行划分. 生活中处处有权限. 比如, 腾讯视频会员才有观看某个最新电影的权限, 你有房间钥匙就有 ...