Source:
Description:
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 (≤), 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 wordon-line
oroff-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 anoff-line
record. Anyon-line
records that are not paired with anoff-line
record are ignored, as areoff-line
records not paired with anon-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 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
Keys:
- 模拟题
Code:
1 /* 2 Data: 2019-07-17 19:24:07 3 Problem: PAT_A1016#Phone Bills 4 AC: 53:32 5 6 题目大意: 7 统计月度话费账单 8 输入: 9 第一行给出,各小时的话费权重cent/minute 10 第二行给出,通话数N<=1e3 11 接下来N行,name,time,status(on/off) 12 输出: 13 打印各个用户的账单,姓名递增 14 name,month 15 start,end,time,costs 16 total amount 17 */ 18 19 #include<cstdio> 20 #include<vector> 21 #include<string> 22 #include<iostream> 23 #include<algorithm> 24 using namespace std; 25 const int M=1e3+10,H=24; 26 struct node 27 { 28 string name,status; 29 string time; 30 }info[M]; 31 struct mode 32 { 33 int dd,hh,mm; 34 }; 35 int n,w[H]; 36 37 bool cmp(const node &a, const node &b) 38 { 39 if(a.name != b.name) 40 return a.name < b.name; 41 else 42 return a.time < b.time; 43 } 44 45 mode Time(string s) 46 { 47 mode t; 48 t.dd = atoi(s.substr(3,2).c_str()); 49 t.hh = atoi(s.substr(6,2).c_str()); 50 t.mm = atoi(s.substr(9,2).c_str()); 51 return t; 52 } 53 54 int Pay(string s1, string s2, int &time, int &cost) 55 { 56 mode t1 = Time(s1); 57 mode t2 = Time(s2); 58 while(t1.dd!=t2.dd || t1.hh!=t2.hh || t1.mm!=t2.mm) 59 { 60 time++; 61 cost += w[t1.hh]; 62 t1.mm++; 63 if(t1.mm==60) 64 { 65 t1.mm=0; 66 t1.hh++; 67 } 68 if(t1.hh==24) 69 { 70 t1.hh=0; 71 t1.dd++; 72 } 73 } 74 return cost; 75 } 76 77 int main() 78 { 79 #ifdef ONLINE_JUDGE 80 #else 81 freopen("Test.txt", "r", stdin); 82 #endif 83 84 for(int i=0; i<H; i++) 85 scanf("%d", &w[i]); 86 scanf("%d", &n); 87 for(int i=0; i<n; i++) 88 cin >> info[i].name >> info[i].time >> info[i].status; 89 sort(info,info+n,cmp); 90 for(int i=1; i<n; i++) 91 { 92 int valid=0,bill=0; 93 while(i<n && info[i-1].name==info[i].name) 94 { 95 int cost=0,time=0; 96 if(info[i-1].status=="on-line"&&info[i].status=="off-line") 97 { 98 if(!valid) cout << info[i].name << " " << info[0].time.substr(0,2) << endl; 99 valid=1; 100 bill += Pay(info[i-1].time,info[i].time,time,cost); 101 cout << info[i-1].time.substr(3) << " " << info[i].time.substr(3); 102 printf(" %d $%.2f\n", time,1.0*cost/100.0); 103 } 104 i++; 105 } 106 if(valid) printf("Total amount: $%.2f\n", 1.0*bill/100.0); 107 } 108 109 return 0; 110 }
来源:https://www.cnblogs.com/blue-lin/p/11203461.html