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. BcdTool(系统启动菜单管理器) v1.0912 绿色版

    软件名称: 系统启动菜单管理器(BcdTool)软件语言: 简体中文授权方式: 免费软件运行环境: Win 32位/64位软件大小: 903KB图片预览: 软件简介:BcdTool是一款windows ...

  2. 移动端touch触屏滑动事件、滑动触屏事件监听!

    一.触摸事件 ontouchstart.ontouchmove.ontouchend.ontouchcancel 目前移动端浏览器均支持这4个触摸事件,包括IE.由于触屏也支持MouseEvent,因 ...

  3. validator验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  4. PHP socket模拟POST请求

    <?php if (! function_exists ( 'socket_post' )) { function socket_post($url, $data, $referer = '') ...

  5. angular模拟elema网页1

    我们之前做的所有的网页项目都用的是假的json数据,真正的前后端的数据交互是个什么情况的呢?现在,我们就来看看. 首先,我们需要进行环境窃取,我们需要一个真实的数据,但是人家公司肯定不会将数据给你的, ...

  6. Flask -- 内容管理系统

    例子: # content_manager.py # 把TOPIC存在一个字典里,key为关键字,value为二维数组# TOPIC_DICT['Django'][0]为Title,TOPIC_DIC ...

  7. oracle 序列介绍

    序列介绍 序列是一个计数器,它并不会与特定的表关联.通过创建Oracle序列和触发器实现表的主键自增. 序列的用途一般用来填充主键和计数. 序列使用 1.创建序列 ORACLE序列的语法格式为: CR ...

  8. linux中将程序加入到开机自动启动

    如果将在linux中将命令或者程序设置为开机自动启动,只需要进入到将对应命令加入到/etc/rc.d/rc.local文件里即可,如下 打开文件,vi /etc/rc.d/rc.local #!/bi ...

  9. C#中Bitmap类 对图像の操作 可检测图片完整性

    try { Bitmap bm = new Bitmap(pics[ip]); BitmapToBytes(bm).Reverse().Take(2); } catch (Exception ex) ...

  10. C#未将对象引用设置到对象的实例

    未将对象引用设置到对象的实例,这个错误的意思是对象为null,但你还要去取里面的值,所以计算机就不干了.解决办法一般是:用一个你不能确定是不是为null的对象时,尽量做个判断.if(object!=n ...