第三天

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&ltstdio.h&gt
#include&ltstdlib.h&gt 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&ltstdio.h&gt
#include&ltstdlib.h&gt
#include&ltstring.h&gt
#define EARLY 1
#define LATE -1

int 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.s

PTA A1005&A1006的更多相关文章

  1. 浙大PTA - - 堆中的路径

    题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21731 本题即考察最小堆的基本操作: #include "iostrea ...

  2. 浙大PTA - - File Transfer

    题目链接:https://pta.patest.cn/pta/test/1342/exam/4/question/21732 #include "iostream" #includ ...

  3. 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 ...

  4. PTA中提交Java程序的一些套路

    201708新版改版说明 PTA与2017年8月已升级成新版,域名改为https://pintia.cn/,官方建议使用Firefox与Chrome浏览器. 旧版 PTA 用户首次在新版系统登录时,请 ...

  5. PTA分享码-Java

    主要用于Java语法练习,非竞赛类题目.   1. Java入门          959dbf0b7729daa61d379ec95fb8ddb0   2. Java基本语法   23bd8870e ...

  6. C语言第一次实验报告————PTA实验1.2.3内容

    一.PTA实验作业 题目1.温度转换 本题要求编写程序,计算华氏温度100°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代 ...

  7. PTA题---求两个有序序列中位数所体现的思想。

    ---恢复内容开始--- 近日,在做PTA题目时,遇到了一个这样的题,困扰了很久.题目如下:已知有两个等长的非降序序列S1, S2, 设计函数求S1与S2并集的中位数.有序序列A​0​​,A​1​​, ...

  8. 第十四,十五周PTA作业

    1.第十四周part1 7-3 #include<stdio.h> int main() { int n; scanf("%d",&n); int a[n]; ...

  9. 第七周PTA作业

    第一题: #include<stdio.h> int main() { ; ; ){ sum=sum+i; i++; } printf("sum = %d\n",sum ...

随机推荐

  1. 常见ASP脚本攻击及防范技巧

    由于ASP的方便易用,越来越多的网站后台程序都使用ASP脚本语言.但是, 由于ASP本身存在一些安全漏洞,稍不小心就会给黑客提供可乘之机.事实上,安全不仅是网管的事,编程人员也必须在某些安全细节上注意 ...

  2. [Spring cloud 一步步实现广告系统] 21. 系统错误汇总

    广告系统学习过程中问题答疑 博客园 Eureka集群启动报错 Answer 因为Eureka在集群启动过程中,会连接集群中其他的机器进行数据同步,在这个过程中,如果别的服务还没有启动完成,就会出现Co ...

  3. Mybatis mapper动态代理的原理详解

    在开始动态代理的原理讲解以前,我们先看一下集成mybatis以后dao层不使用动态代理以及使用动态代理的两种实现方式,通过对比我们自己实现dao层接口以及mybatis动态代理可以更加直观的展现出my ...

  4. MySQL隔离性及Spring事务

    一.数据库事务ACID特性 必须要掌握事务的4个特性,其中事务的隔离性之于MySQL,对应4级隔离级别. 原子性(Atomicity): 事务中的所有原子操作,要么都能成功完成,要么都不完成,不能停滞 ...

  5. java 正则 替换中文为空

    //中文替换为"" public String replaceChineseToNULL(String s){ String reg = "[\u4e00-\u9fa5] ...

  6. 2019牛客暑期多校训练营(第十场)J - Wood Processing (斜率优化DP)

    >传送门< 题意 $n$个宽度为$w_{i}$,高为$h_{i}$ 的 木块,要求分成$k$组,对于每组内的所有木块,高度都变为组内最低木块的高度,宽度保持不变,求变化的最小面积. 分析 ...

  7. N个tomcat之间实现Session共享(写的不错,转来的)

    以下文章写的比较不错,转来的. tomcat的session共享设置如此简单为什么很少人去用.这个我说的重点. 1.自身的session如果服务器不在同一个网段会有session失效(本人使用的是阿里 ...

  8. 记:使用vue全家桶 + vux组件库 打包成 dcloud 5+ app 开发过程中遇到的问题

    vue-cli 版本:2.9.6   webpack 版本:3.6.0 1. vue-cli 安装好之后,不是自动打开默认浏览器 在 config文件夹 ---> dev选项中,有个 autoO ...

  9. egret之纹理填充模式(上下填充)

    首先,我们准备两张图片,一张作为背景“瓶子”,一张作位填充物“饮料”. 在皮肤里我们设置右边图片的填充模式为“repeat”,修改Y的缩放为:-1.,调整图片位置使之与地图重合,如下: 现在,我们可以 ...

  10. 微软发布了开发社区采用.NET Standard的最新信息

    最近,微软发布了开发社区当前采用.NET Standard的最新信息..NET Standard是API的正式规范,现有.NET实现在不同平台的是通用的(从而允许跨平台开发).当前规范(版本2.0)在 ...