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. 【Machine Learning in Action --5】逻辑回归(LogisticRegression)

    1.概述 Logistic regression(逻辑回归)是当前业界比较常用的机器学习方法,用于估计某种事物的可能性. 在经典之作<数学之美>中也看到了它用于广告预测,也就是根据某广告被 ...

  2. 将MyEclipse中的项目导入到Eclipse中报错的解决放法

    1.导入项目后,会报红色感叹号, 将项目右键,点击红色框.

  3. 【3】docker命令集

    root@xcc-VirtualBox:/home/xcc# docker --helpUsage: docker [OPTIONS] COMMAND [arg...]       docker [ ...

  4. linux服务器出现严重故障后的原因以及解决方法

    1.把系统安装光盘插入,重启机器,启动时迅速按下Del键,进入CMOS,把启动顺序改为光盘先启动,这样就启动了Linux安装程序,按F5,按提示打入Linux rescue回车,进入救援模式,接下来是 ...

  5. MFC模态和非模态对话框编程

    MFC中对话框有两种形式,一个是模态对话框(model dialog box),一个是非模态对话框(modeless dialog box). 一.模态对话框(model dialog box) 在程 ...

  6. H5的新应用-指定视频的播放进度

    <!DOCTYPE html> <html> <head> <title>指定视频的播放进度</title> <meta http-e ...

  7. css3 media媒体查询器用法总结 兼容ie8以下的方法

    总结一下响应式设计的核心CSS技术Media(媒体查询器)的用法. http://www.360doc.com/content/14/0704/06/10734150_391862769.shtml ...

  8. HTML/CSS font-family对应的中英文名称 宋体 微软雅黑

    宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 PMingLiU 细明体 Ming ...

  9. anyremote源码分析

    XTest   鼠标移动事件. XTestFakeMotionEvent 关于XTest的编程. http://lilydjwg.is-programmer.com/2011/9/21/using-x ...

  10. java基础概念经典题目汇集

    1.下面是People和Child类的定义和构造方法,每个构造方法都输出编号.在执行new Child("mike")的时候都有哪些构造方法被顺序调用?请选择输出结果 ( ) cl ...