PAT1016
A long-distance telephone company charges its customers by the following rules:
一個長途電話公司費用告訴它的顧客需要遵循以下的規(guī)則
Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made.
打一個長途電話一分鐘的費用是依據(jù)什么時候撥打這個電話計算得到的。
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.
當(dāng)一個顧客開始連接長途電話的時候,時間會被記錄,直到當(dāng)用戶掛掉這個電話為止。
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.
你的任務(wù)是準(zhǔn)備著每個月的賬單,給出一個電話記錄的集合。
Input Specification:
Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.
每個輸入文件包含一個測試用例。每個測試用例有兩個部分,頻率結(jié)構(gòu),和電話記錄
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.
頻率結(jié)構(gòu)包含一行,用24個正整數(shù)組成,表示每一個小時的收費
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的正整數(shù),下面N行記錄,每個電話記錄包含顧客的名字,20個字符以內(nèi)沒有空格,時間和日期,和一個詞"on-line" or "off-line".
For each test case, all dates will be within a single month.
對于每個測試用例所有的日期都將會在一個單月之內(nèi)
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" 記錄是成對出現(xiàn)的,而且是按時間順序的。
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"記錄成對出現(xiàn)的"on-line" 記錄都被忽略,對于沒有"on-line" 記錄相對應(yīng)得"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.
至少會有一個電話記錄成對出現(xiàn)在輸入文件中。你可以確定沒有兩個記錄對于同一個顧客同一個時間是一模一樣的,時間記錄使用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.
對于每個時間的電話,打印出一行開始和結(jié)束的時間和日期,最后的時間和費用。電話必須以時間順序的,最后打印一個這個月的總費用。
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-lineSample 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. 但是如果這個人沒有任何記錄是匹配的,那么這個人是不能輸出任何信息的,也就是沒有他這個人的賬單。
?
主要利用排序,其他都是邏輯上面比較繁瑣而已。
?
下面補(bǔ)充qsort中的使用方法。題目就只是考了這個而已,沒有別的算法。
?
七種qsort排序方法
<本文中排序都是采用的從小到大排序>
一、對int類型數(shù)組排序
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類型數(shù)組排序(同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類型數(shù)組排序(特別要注意)
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);
四、對結(jié)構(gòu)體一級排序
struct In
{
double data;
int other;
}s[100]
//按照data的值從小到大將結(jié)構(gòu)體排序,關(guān)于結(jié)構(gòu)體內(nèi)的排序關(guān)鍵數(shù)據(jù)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);
五、對結(jié)構(gòu)體二級排序
struct In
{
int x;
int y;
}s[100];
//按照x從小到大排序,當(dāng)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);
六、對字符串進(jìn)行排序
struct In
{
int data;
char str[100];
}s[100];
//按照結(jié)構(gòu)體中字符串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函數(shù),把除了1點外的所有點,旋轉(zhuǎn)角度排序
{
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)) //如果在一條直線上,則把遠(yuǎn)的放在前面
return 1;
else return -1;
}
PS:
其中的qsort函數(shù)包含在<stdlib.h>的頭文件里,strcmp包含在<string.h>的頭文件里
轉(zhuǎn)載于:https://www.cnblogs.com/linkstar/p/5758570.html
總結(jié)
- 上一篇: 【EF学习笔记09】----------
- 下一篇: 利用WCF的双工通讯实现一个简单的心跳监