PTA A1005&A1006
第三天
A1005 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
单词
consecutive
英 /kən'sekjʊtɪv/ 美 /kən'sɛkjətɪv/
adj. 连贯的;连续不断的
compute
英 /kəm'pjuːt/ 美 /kəm'pjʊt/
n. 计算;估计;推断
vt. 计算;估算;用计算机计算
vi. 计算;估算;推断
题目分析
这题还是很简单的,10的100次方显然超过了int的范围,long int可能都不行,所以这题肯定不能用处理数字的方法解决,所以我把这个数字看作字符,相加时把每个字符减去一个'0',然后再用sprintf把数字改为字符串,代码如下。
具体代码
#include<stdio.h>
#include<stdlib.h> const char *ch[] = { "zero","one","two","three","four","five","six","seven","eight","nine" };
int N;
int main(void)
{
char c[101];
int i = 0;
while ((c[i] = getchar()) != '\n')i++;
int sum = 0;
while (i--)
{
sum += c[i] - '0';
}
char c2[101];
sprintf(c2, "%d", sum);
printf("%s", ch[c2[0] - '0']);
i = 1;
while (c2[i] != '\0')
{
printf(" %s", ch[c2[i] - '0']);
i++;
}
system("pause");
}
A1006 Sign In and Sign Out (25 分)
题目内容
At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.
Input Specification:
Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:
ID_number Sign_in_time Sign_out_time
where times are given in the format HH:MM:SS, and ID_number is a string with no more than 15 characters.
Output Specification:
For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.
Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.
Sample Input:
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
Sample Output:
单词
题目分析
过于简单,无话可说。
具体代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define EARLY 1
#define LATE -1int M;
struct time
{
int h;
int m;
int s;
};struct time earliest_time;
struct time lastest_time;char earliest_id[16];
char lastest_id[16];int compare_time(struct time t1, struct time t2);
int main(void)
{
earliest_time.h = 23;
earliest_time.m = 59;
earliest_time.s = 59;
lastest_time.h = 0;
lastest_time.m = 0;
lastest_time.s = 0;
scanf("%d", &M);
while (M--)
{
struct time in;
struct time out;
char id[16];
scanf("%s %d:%d:%d %d:%d:%d", id, &in.h, &in.m, &in.s, &out.h, &out.m, &out.s);
if (compare_time(in, earliest_time) == EARLY)
{
earliest_time.h = in.h;
earliest_time.m = in.m;
earliest_time.s = in.s;
strcpy(earliest_id, id);
}
if (compare_time(out, lastest_time) == LATE)
{
lastest_time.h = out.h;
lastest_time.m = out.m;
lastest_time.s = out.s;
strcpy(lastest_id, id);
}
}
printf("%s %s", earliest_id, lastest_id);
system("pause");
}int compare_time(struct time t1, struct time t2)
{
if (t1.h > t2.h)
return LATE;
else if (t1.h t2.m)
return LATE;
else if (t1.m t2.s)
return LATE;
else if (t1.sPTA A1005&A1006的更多相关文章
- 浙大PTA - - 堆中的路径
题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...
- 浙大PTA - - File Transfer
题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...
- ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection Bind through PTA failed (91). Retrying...
LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ...
- PTA中提交Java程序的一些套路
201708新版改版说明 PTA与2017年8月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...
- PTA分享码-Java
主要用于Java语法练习,非竞赛类题目. 1. Java入门 959dbf0b7729daa61d379ec95fb8ddb0 2. Java基本语法 23bd8870e ...
- C语言第一次实验报告————PTA实验1.2.3内容
一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...
- PTA题---求两个有序序列中位数所体现的思想。
---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数.有序序列A0,A1, ...
- 第十四,十五周PTA作业
1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...
- 第七周PTA作业
第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...
随机推荐
- Redis 5.0.5集群搭建
Redis 5.0.5集群搭建 一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):s ...
- 清缓存的姿势不对,真的会出生产bug哦
最近解决了一个生产bug,bug的原因很简单,就是清理缓存的方式不对.本来没啥好说的,但是考虑到我们有时候确实会在一些小问题上栽跟头,最终决定把这个小故事拿出来跟大家分享下. 风起有一天在撸代码,突然 ...
- iOS 11 变化
首先我是开发者,更关心对技术的影响,我又需要关注.学习哪些技术,猫神的文章:http://www.cocoachina.com/ios/20170607/19457.html 介绍了 ******** ...
- Excel VBA 在保留原单元格数据的情况下,将计算的百分比加在后面
算的是红框占绿框的百分比 难点在保留原数据的情况下,把百分比加在后面.通过公式我是不会,但程序实现也不难. 先在Excel中的开发工具中打开visual basic,或者用宏也可以 导入代码文件,代码 ...
- ABAP实现Geohash
前几天群里有人问ABAP有没有Geohash函数,用来帮助SAP存储门店位置.实现对附近门店查找的功能.因为没有查到,所以我动手写了一个. Geohash是什么 Geohash是一种公共域地理编码系统 ...
- 王某人从0开始学习lorawan的笔记_1:最底层!IO驱动层,Gpio_t类
本来想介绍SX1276(与SX1278的操作完全相同,只是需要处理频段)的,但是这款芯片内容还是很丰富的,三言两语介绍不清,而且资料也很多就算了. 直接正面怼lorawan吧,怼到高地去,打爆lora ...
- 关于简单递归在python3中的实现
话不多说,奉上代码: #倒计时 def count_down(i): if i <= 0: return else: print(str(i)) count_down(i - 1) #求阶乘 d ...
- Java NIO系列之[说在前面的话]
在开始这个系列文章之前,先聊一些题外话,说说我为什么要写Java NIO这个系列技术文章(不看完会错失一个亿的),因为Java NIO并不像JVM,中间件源码那么有吸引力,但这个技术点是java的基础 ...
- String类的intern()方法,随常量池发生的变化
JVM的知识这里总结的很详细:https://github.com/doocs/jvm/blob/master/README.md,因此在本博客也不会再对其中的东西重复总结了. intern的作用 简 ...
- 快速掌握SPSS数据分析
SPSS难吗?无非就是数据类型的区别后,就能理解应该用什么样的分析方法,对应着分析方法无非是找一些参考资料进行即可.甚至在线网页SPSS软件直接可以将数据分析结果指标人工智能地分析出来,这有多难呢 ...