1016. Phone Bills (25)
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 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
https://www.patest.cn/contests/pat-a-practise/1016
https://www.nowcoder.com/questionTerminal/e9d0bb5a8e00482b9f1f36dd058c26ff
思路:
超级麻烦的模拟题
坑点:
同天同小时的情况
CODE:
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#define N 1010
using namespace std;
map<string,int> ma;
typedef struct S
{
string _n;
string _t;
string _l;
};
typedef struct A
{
string name;
string _sta;
string _end;
int ccc;
int _co;
};
typedef struct B
{
string na;
A re[500];
int tol;
int nuu;
};
S rec[N];
A rec1[N];
B ult[N];
int cost[24];
bool cmp(S a,S b)
{
if (a._n==b._n)
{
if (a._t==b._t)
{
return a._l>b._l;
}
else
return a._t<b._t;
}
else
return a._n<b._n;
}
bool cmp1(B a, B b)
{
return a.na<b.na;
}
int main()
{
for (int i=0;i<24;i++) cin>>cost[i];
int n;
cin>>n;
for (int i=0;i<n;i++)
{
cin>>rec[i]._n>>rec[i]._t>>rec[i]._l;
}
string yf=rec[0]._t.substr(0,2);;
sort(rec,rec+n,cmp);
//cout<<endl<<endl;
//for (int i=0;i<n;i++) cout<<rec[i]._n<<rec[i]._t<<rec[i]._l<<endl;
int nuum=0;
for (int i=0;i<n;i++)
{
//cout<<i<<" "<<rec[i]._l<<endl;
if (rec[i]._l=="off-line") continue;
if (rec[i]._l=="on-line")
{
// cout<<i<<endl;
if (i==n-1) continue;
if (rec[i+1]._n!=rec[i]._n) continue;
if (rec[i+1]._l!="off-line") continue;
A t;
t.name=rec[i]._n;
t.ccc=0;
t._sta=rec[i]._t.substr(3,rec[i]._t.length()-3);
t._end=rec[i+1]._t.substr(3,rec[i+1]._t.length()-3);
//cout<<t._sta.substr(0,2)<<" "<<t._sta.substr(0,2)<<endl;
if (t._sta.substr(0,2)!=t._end.substr(0,2))
{
int co=0;
int sum=0;
for (int k=0;k<24;k++)
sum+=60*cost[k];
for (int j=atoi(t._sta.substr(0,2).c_str())+1;j<atoi(t._end.substr(0,2).c_str());j++)
{
t.ccc+=1440;
co+=sum;
}
//cout<<co<<" ";
t.ccc+=60-atoi(t._sta.substr(6,2).c_str());
t.ccc+=atoi(t._end.substr(6,2).c_str());
co+=cost[atoi(t._sta.substr(3,2).c_str())]*(60-atoi(t._sta.substr(6,2).c_str()));
co+=cost[atoi(t._end.substr(3,2).c_str())]*(atoi(t._end.substr(6,2).c_str()));
for (int j=atoi(t._sta.substr(3,2).c_str())+1;j<24;j++)
{
t.ccc+=60;
co+=cost[j]*60;
}
//cout<<co<<" ";
for (int j=0;j<atoi(t._end.substr(3,2).c_str());j++)
{
t.ccc+=60;
co+=cost[j]*60;
}
//cout<<co<<endl;
t._co=co;
}
else
{
if (t._sta.substr(3,2)==t._end.substr(3,2))
{
int co=0;
t.ccc+=atoi(t._end.substr(6,2).c_str())-atoi(t._sta.substr(6,2).c_str());
t._co=t.ccc*cost[atoi(t._sta.substr(3,2).c_str())];
}
else
{
int co=0;
for (int j=atoi(t._sta.substr(3,2).c_str())+1;j<atoi(t._end.substr(3,2).c_str());j++)
{
t.ccc+=60;
co+=cost[j]*60;
}
t.ccc+=60-atoi(t._sta.substr(6,2).c_str());
t.ccc+=atoi(t._end.substr(6,2).c_str());
co+=cost[atoi(t._sta.substr(3,2).c_str())]*(60-atoi(t._sta.substr(6,2).c_str()));
co+=cost[atoi(t._end.substr(3,2).c_str())]*(atoi(t._end.substr(6,2).c_str()));
t._co=co;
}
}
rec1[nuum]=t;
nuum++;
}
}
//for (int i=0;i<nuum;i++) cout<<rec1[i].name<<" "<<rec1[i]._sta<<" "<<rec1[i]._end<<" "<<rec1[i]._co<<endl;
int nn=0;
ult[nn].nuu=0;
ult[nn].tol=0;
for (int i=0;i<nuum;i++)
{
ult[nn].na=rec1[i].name;
ult[nn].re[ult[nn].nuu]=rec1[i];
ult[nn].nuu++;
ult[nn].tol+=rec1[i]._co;
if (rec1[i+1].name!=rec1[i].name)
{
nn++;
ult[nn].nuu=0;
ult[nn].tol=0;
}
}
sort(ult,ult+nn,cmp1);
for (int i=0;i<nn;i++)
{
printf("%s %s\n",ult[i].na.c_str(),yf.c_str());
//cout<<ult[i].na<<" "<<yf<<endl;
for (int j=0;j<ult[i].nuu;j++)
{
cout<<ult[i].re[j]._sta<<" "<<ult[i].re[j]._end<<" "<<ult[i].re[j].ccc<<" $";
printf("%.2f\n",ult[i].re[j]._co/100.0);
}
//cout<<ult[i].re[j]._sta<<" "<<ult[i].re[j]._end<<" "<<ult[i].re[j]._co<<endl;
//cout<<ult[i].tol<<endl<<endl;
printf("Total amount: $%.2f\n",ult[i].tol/100.0);
}
return 0;
}