PAT1016
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的更多相关文章
- pat1016. Phone Bills (25)
1016. Phone Bills (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A long-di ...
- PAT1016 × PAT1017
本次题解是综合1016和1017两道题来讲解,原因无他,因为这两道都是模拟题,综合字符串处理.排序等考点 接手一道模拟题,一定要快速且准确地了解模拟的过程,清晰题目涉及的关键信息.比如1016要计算电 ...
- PAT甲级1016. Phone Bills
PAT甲级1016. Phone Bills 题意: 长途电话公司按以下规定向客户收取费用: 长途电话费用每分钟一定数量,具体取决于通话时间.当客户开始连接长途电话时,将记录时间,并且客户挂断电话时也 ...
随机推荐
- 设n是奇数,证明:16|(n4+4n2+11)(整除原理1.1.1)
设n是奇数,证明:16|(n4+4n2+11) 解: 令n=2k+1,k∈z n4+4n2+11 =(2k+1)4+4(2k+1)2+11 =(4k2+4k+1)2+(2k+1)2+11 =16k4+ ...
- iosOC不可变数组遍历
NSArray * array = @[@"1",@"2",@"3"]; NSLog(@"%@",array); //1 ...
- VB.net结束进程
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...
- C语言_基础代码_01
#include<stdio.h> #include<stdlib.h> #define BUFFERSIZE 1024/*允许处理的最长行有1024个字符*/ /*编译环境v ...
- redis运维的一些知识点
恰好看到一些redis需要主要的东西 记下 供参考 原文地址 http://hi.baidu.com/ywdblog/item/1a8c6ed42edf01866dce3fe3 最近在线上实际使用了一 ...
- DOM操作-根据name获取网页中的全部复选框
描述: 与id不同,多个元素可以使用相同的name属性,如果需要获取这一类元素的DOM对象,就需要使用getElementsByName()函数 代码: <!DOCTYPE html> & ...
- 一个机器学习博客 ,包括 Standford公开课machine learning
http://blog.csdn.net/abcjennifer/article/category/1173803/4 http://blog.csdn.net/abcjennifer/article ...
- HDU4310:Hero
Problem Description When playing DotA with god-like rivals and pig-like team members, you have to fa ...
- 获得正在编辑行的数据 esayui datagrid
function getEditRow(datagridId) {//datagridId为table容器的id var input = $('#' + datagridId).parent().fi ...
- ECShop - 数据库操作类
ECShop v2.7.2没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现.这样做的好处是实现非常轻量,只有一个文件,27Kb,大大减小了分发包的文件大小.另外,当网站 ...