A1016 Phone Bills (25 point(s))

电话服务

1. 原文

原题

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:

1
2
3
4
5
6
7
8
9
10
11
12
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:

1
2
3
4
5
6
7
8
9
10
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

2. 解析

将给出的数据按照姓名排序,在按照时间的先后顺序排列。姓名相同的状态先后为on-line,off-line的才为合格的数据

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
char name[30];
int month,day,hour,minute,status;
}customer[1010];
int toll[25]={};
char status[10];
bool cmp(node a,node b){
int temp = strcmp(a.name,b.name);
if (temp!=0)
{
return temp<0;
}else if(a.month!=b.month){
return a.month<b.month;
}else if(a.day!=b.day){
return a.day<b.day;
}else if(a.hour!=b.hour){
return a.hour<b.hour;
}else{
return a.minute<b.minute;
}
}
vector<node> ans;
int sub(node a,node b){
int suba = a.day*24*60+a.hour*60+a.minute;
int subb = b.day*24*60+b.hour*60+b.minute;
return subb-suba;
}
double getToll(node a){
double sum = toll[a.hour]*a.minute+toll[24]*a.day*60;
for (int i = 0; i < a.hour; ++i)
{
sum+=toll[i]*60;
}
return sum/100.0;
}
int main(){
freopen("A1016.txt","r",stdin);
for (int i = 0; i < 24; ++i)
{
scanf("%d",&toll[i]);
toll[24]+=toll[i];
}
int n;
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
node temp;
scanf("%s %d:%d:%d:%d %s",temp.name,
&temp.month,&temp.day,&temp.hour,&temp.minute,status);
if (strcmp(status,"on-line")==0)
{
temp.status = 1;
}else{
temp.status = -1;
}
customer[i]=temp;
}
sort(customer,customer+n,cmp);
for (int i = 1; i < n; ++i)
{
if (strcmp(customer[i].name,customer[i-1].name)==0&&
customer[i].status==-1&&customer[i-1].status==1)
{
ans.push_back(customer[i-1]);
ans.push_back(customer[i]);
}
}
double total = 0;
bool flag = true;
for (int i = 0; i < ans.size(); ++i)
{
if(flag){
printf("%s %02d\n",ans[i].name,ans[i].month);
}
double temp = getToll(ans[i+1])-getToll(ans[i]);
printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n",
ans[i].day,ans[i].hour,ans[i].minute,
ans[i+1].day,ans[i+1].hour,ans[i+1].minute,sub(ans[i],ans[i+1]),temp);
i++;
total+=temp;
if (strcmp(ans[i].name,ans[i+1].name)!=0)
{
printf("Total amount: $%.2f\n",total);
total=0;
flag = true;
}else{
flag = false;
}

}


return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/03/A1016/
  • 发布时间: 2019-09-03 12:35
  • 更新时间: 2021-10-29 13:59
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!