A long-distance telephone company charges its customers by the following rules:

一个长途电话公司费用告诉它的顾客需要遵循以下的规则

Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made.

打一个长途电话一分钟的费用是依据什么时候拨打这个电话计算得到的。

When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone.

当一个顾客开始连接长途电话的时候,时间会被记录,直到当用户挂掉这个电话为止。

Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day).

每个月,一个账单会送到顾客手中对于每一分钟拨打,频率是以每天计算的。

Your job is to prepare the bills for each month, given a set of phone call records.

你的任务是准备着每个月的账单,给出一个电话记录的集合。

Input Specification:

Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.

每个输入文件包含一个测试用例。每个测试用例有两个部分,频率结构,和电话记录

The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.

频率结构包含一行,用24个正整数组成,表示每一个小时的收费

The next line contains a positive number N (<= 1000), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (mm:dd:hh:mm), and the word "on-line" or "off-line".

下面一行包含一个小于1000的正整数,下面N行记录,每个电话记录包含顾客的名字,20个字符以内没有空格,时间和日期,和一个词"on-line" or "off-line".

For each test case, all dates will be within a single month.

对于每个测试用例所有的日期都将会在一个单月之内

Each "on-line" record is paired with the chronologically next record for the same customer provided it is an "off-line" record.

每个"on-line" 记录和"off-line" 记录是成对出现的,而且是按时间顺序的。

Any "on-line" records that are not paired with an "off-line" record are ignored, as are "off-line" records not paired with an "on-line" record.

任何没有与"off-line"记录成对出现的"on-line" 记录都被忽略,对于没有"on-line" 记录相对应得"off-line"记录也一样。

It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.

至少会有一个电话记录成对出现在输入文件中。你可以确定没有两个记录对于同一个顾客同一个时间是一模一样的,时间记录使用24小时制。

Output Specification:

For each test case, you must print a phone bill for each customer.

对于每个测试用例你需要打印出每个用户的电话账单

Bills must be printed in alphabetical order of customers' names.

账单必须以客户名称的字母序排列

For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample.

对于每个用户,先打印一行名字,然后一个月的账单格式如下。

Then for each time period of a call, print in one line the beginning and ending time and date (dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.

对于每个时间的电话,打印出一行开始和结束的时间和日期,最后的时间和费用。电话必须以时间顺序的,最后打印一个这个月的总费用。

Sample Input:

10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
10
CYLL 01:01:06:01 on-line
CYLL 01:28:16:05 off-line
CYJJ 01:01:07:00 off-line
CYLL 01:01:08:03 off-line
CYJJ 01:01:05:59 on-line
aaa 01:01:01:03 on-line
aaa 01:02:00:01 on-line
CYLL 01:28:15:41 on-line
aaa 01:05:02:24 on-line
aaa 01:04:23:59 off-line

Sample Output:

CYJJ 01
01:05:59 01:07:00 61 $12.10
Total amount: $12.10
CYLL 01
01:06:01 01:08:03 122 $24.40
28:15:41 28:16:05 24 $3.85
Total amount: $28.25
aaa 01
02:00:01 04:23:59 4318 $638.80
Total amount: $638.80

这道题主要问题死在题目中说了 It is guaranteed that at least one call is well paired in the input. 但是如果这个人没有任何记录是匹配的,那么这个人是不能输出任何信息的,也就是没有他这个人的账单。

主要利用排序,其他都是逻辑上面比较繁琐而已。

下面补充qsort中的使用方法。题目就只是考了这个而已,没有别的算法。

七种qsort排序方法

<本文中排序都是采用的从小到大排序>

一、对int类型数组排序

int num[100];

Sample:

int cmp ( const void *a , const void *b )
{

return *(int *)a - *(int *)b;

}

qsort(num,100,sizeof(num[0]),cmp);

二、对char类型数组排序(同int类型)

char word[100];

Sample:

int cmp( const void *a , const void *b )

{

return *(char *)a - *(int *)b;

}

qsort(word,100,sizeof(word[0]),cmp);

三、对double类型数组排序(特别要注意)

double in[100];

int cmp( const void *a , const void *b )

{

return *(double *)a > *(double *)b ? 1 : -1;

}

qsort(in,100,sizeof(in[0]),cmp);

四、对结构体一级排序

struct In

{

double data;

int other;

}s[100]

//按照data的值从小到大将结构体排序,关于结构体内的排序关键数据data的类型可以很多种,参考上面的例子写

int cmp( const void *a ,const void *b)

{

return (*(In *)a).data > (*(In *)b).data ? 1 : -1;

}

qsort(s,100,sizeof(s[0]),cmp);

五、对结构体二级排序

struct In

{

int x;

int y;

}s[100];

//按照x从小到大排序,当x相等时按照y从大到小排序

int cmp( const void *a , const void *b )

{

struct In *c = (In *)a;

struct In *d = (In *)b;

if(c->x != d->x) return c->x - d->x;

else return d->y - c->y;

}

qsort(s,100,sizeof(s[0]),cmp);

六、对字符串进行排序

struct In

{

int data;

char str[100];

}s[100];

//按照结构体中字符串str的字典顺序排序

int cmp ( const void *a , const void *b )

{

return strcmp( (*(In *)a)->str , (*(In *)b)->str );

}

qsort(s,100,sizeof(s[0]),cmp);

七、计算几何中求凸包的cmp

int cmp(const void *a,const void *b) //重点cmp函数,把除了1点外的所有点,旋转角度排序

{

struct point *c=(point *)a;

struct point *d=(point *)b;

if( calc(*c,*d,p[1]) < 0) return 1;

else if( !calc(*c,*d,p[1]) && dis(c->x,c->y,p[1].x,p[1].y) < dis(d->x,d->y,p[1].x,p[1].y)) //如果在一条直线上,则把远的放在前面

return 1;

else return -1;

}

PS:

其中的qsort函数包含在<stdlib.h>的头文件里,strcmp包含在<string.h>的头文件里

PAT1016的更多相关文章

  1. pat1016. Phone Bills (25)

    1016. Phone Bills (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-di ...

  2. PAT1016 × PAT1017

    本次题解是综合1016和1017两道题来讲解,原因无他,因为这两道都是模拟题,综合字符串处理.排序等考点 接手一道模拟题,一定要快速且准确地了解模拟的过程,清晰题目涉及的关键信息.比如1016要计算电 ...

  3. PAT甲级1016. Phone Bills

    PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...

随机推荐

  1. css格式布局

    一.position:fixed 锁定位置(相对于浏览器的位置),例如有些网站的右下角的弹出窗口. 示例 : 二.position:absolute 1.外层没有position:absolute(或 ...

  2. Zookeeper 启动错误

    启动后日志如下 : 2016-09-14 05:51:19,449 [myid:1] - INFO [QuorumPeer[myid=1]/0:0:0:0:0:0:0:0:2181:FastLeade ...

  3. List泛型集合常用方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace List ...

  4. GitHub上有很多不错的iOS开源项目

    GitHub上有很多不错的iOS开源项目,个人认为不错的,有这么几个:1. ReactiveCocoa:ReactiveCocoa/ReactiveCocoa · GitHub:GitHub自家的函数 ...

  5. 《JavaScript高级程序设计》读书笔记 ---执行环境及作用域

    执行环境及作用域 执行环境(execution context,为简单起见,有时也称为“环境”)是JavaScript 中最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了它们各自 ...

  6. Flask -- 静态文件 和 模板渲染

    静态文件 一般用于存放图片,样式文件(css, js等) 保存位置:包中或者文件所在目录创建一个 static 目录 访问:在应用中使用 /static/...即可访问 , 更好的方式是使用url_f ...

  7. mysql分页的问题

    用过mysql的人肯定知道,mysql提供了原生的分页功能-----LIMIT关键字.LIMIT 子句可以被用于强制 SELECT 语句返回指定的记录数.LIMIT 接受一个或两个数字参数.参数必须是 ...

  8. 解决VS2010中winsock.h与winsock2.h冲突(重复定义)——转载

    解决VS2010中winsock.h与winsock2.h冲突(重复定义)——转载 当这两个头文件顺序颠倒时,编译会出现许多莫名其妙的错误,错误如下: 1>…\include\ws2def.h( ...

  9. VBS控制鼠标移动和点击(附源代码下载)

    森思:想用vbs来控制鼠标的移动和点击,虽然按键精灵可以做到,但做这么简单的事情不想启动那么大一个程序,所以自己用VC写了一个小程序,可以让VBS来控制鼠标移动和点击. 用法: 移动鼠标到桌面坐标20 ...

  10. csu1010: Water Drinking

    /* 本题的题意: 沙漠中有很多骆驼和一个池塘,0表示池塘,1-N表示骆驼,输入的两个数表示两只骆驼,其中前面的那一头靠近池塘,所有的骆驼队列不交叉不相连,求站在队尾但是离水井最近的骆驼编号 经过分析 ...