PAT 甲级 1016 Phone Bills
发布日期:2021-07-01 03:08:51 浏览次数:2 分类:技术文章

本文共 5861 字,大约阅读时间需要 19 分钟。

1016 Phone Bills (25 point(s))

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.

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.

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. 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. 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.

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 1010CYLL 01:01:06:01 on-lineCYLL 01:28:16:05 off-lineCYJJ 01:01:07:00 off-lineCYLL 01:01:08:03 off-lineCYJJ 01:01:05:59 on-lineaaa 01:01:01:03 on-lineaaa 01:02:00:01 on-lineCYLL 01:28:15:41 on-lineaaa 01:05:02:24 on-lineaaa 01:04:23:59 off-line

Sample Output:

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

Experiential Summing-up

This question seems very difficult. As a matter of effect, The hard point lie in phone bill's calculation and understand the method of match two record. Really, it's not so hard. Here I mainly talk about the way of judging whether the record legal or not.

Each on-line record is paired with the chronologically next record for the same customer provided it is an off-line record. 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. This description test our comprehension of English. Firstly, we need to sort out the record of the same customer chronologically ( that is by time). Then, the first legal record's status is on-line, if the next record's status is also on-line. The former will become illegal and abandoned, but if the next record's status is off-line. The former and the latter will be matched.
If the first legal record's status is off-line, you can discard it straightly and judge the next. I hope I explain it clearly. The other thing just easy to overcome. But the premise is you can utilize STL proficiently~~

(The purpose of using English to portray my solution is that to exercise the ability of my expression of English and accommodate PAT advanced level's style.We can make progress together by reading and comprehending it. Please forgive my basic grammar's and word's error. Of course, I would appreciated it if you can point out my grammar's and word's error in comment section.( •̀∀•́ ) Furthermore, Big Lao please don't laugh at me because I just a English beginner settle for CET6    _(:з」∠)_  )

Accepted Code

#include 
#include
#include
#include
#include
#include
#include
using namespace std;int rate[25];struct bill{ string start,end; int time; double cost;};bool cmp1(pair
a,pair
b){ return a.first
=60) { m1=0; ++h1; } if(h1>=24) { h1=0; ++d1; } } return cost;}int main(){ int n; for(int i=0;i<24;++i) scanf("%d",&rate[i]); scanf("%d",&n); string name,time,flag; map
> >mp; for(int i=0;i
>name>>time>>flag; if(flag=="on-line") mp[name].push_back(make_pair(time,true)); else mp[name].push_back(make_pair(time,false)); } map
>mp1; for(map
> >::iterator it=mp.begin();it!=mp.end();++it) { int f=1,pre; sort(it->second.begin(),it->second.end(),cmp1); for(int i=0;i
second.size();++i) { if(it->second[i].second==f) { if(f==0) { bill a; a.start=it->second[pre].first; a.end=it->second[i].first; a.cost=compute(a.start,a.end,a.time); mp1[it->first].push_back(a); } else { pre=i; } f=f?0:1; } else { if(it->second[i].second==1) { pre=i; } } } } for(map
>::iterator it=mp1.begin();it!=mp1.end();++it) { sort(it->second.begin(),it->second.end(),cmp2); printf("%s %s\n",it->first.c_str(),it->second[0].start.substr(0,2).c_str()); double sum=0; for(int i=0;i
second.size();++i) { double temp=it->second[i].cost/100; printf("%s %s %d $%.2f\n",it->second[i].start.substr(3,8).c_str(),it->second[i].end.substr(3,8).c_str(),it->second[i].time,temp); sum+=temp; } printf("Total amount: $%.2f\n",sum); } return 0;}

 

转载地址:https://meteorrain.blog.csdn.net/article/details/86557759 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT 甲级 1017 Queueing at Bank
下一篇:PAT 甲级 1015 Reversible Primes

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年05月04日 15时25分07秒