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 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-linerecord. 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
0, 1 Test Point: Users without consumption cannot output
2 Test point: on and off dates are not on the same day but on the same hour
3 Test points: on and off dates are the same day and hour
Topic:
A long-distance telephone company fee rule is as follows:
Long distance calls are charged a fixed fee per minute, depending on the time of the call.When a customer's long distance call is connected, the moment is recorded, as is when the customer hangs up.Every month, the phone bill for each minute of a call is sent to the customer.Your job is to prepare your monthly bill and give you a list of phone calls.
Each test sample has two parts: rate structure and call log
The rate structure consists of a row of 24 non-negative integers that record long-distance telephone charges (cents per minute) for 24 hours per hour a day.
The next line contains a positive number N (< 1000), followed by N records, each phone call record containing the customer's name (a 20-character string with no spaces) time (mm:dd:hh:mm) and text on-line or off-line
For each test case, all data is within one month.Each on-line record will have the next chronological record (the same customer name) in off-line status, which forms a pair.If some on-line records do not have an off-line record that can be paired, ignore this record, and if only the off-line record does not have a corresponding on-line record, ignore it.At least one phone record can be paired.You can assume that there won't be two records for the same customer at the same time.Use a 24-hour clock to record time
For each test sample, you need to print out a phone bill for each customer
Phone bills are printed in alphabetical order by customer name.For each customer, print out the month of the customer's name and bill first.Then, for each call period, print out the start time and end time and date (dd:hh:mm), duration (in minutes), and charge with one line.All calls are listed in chronological order.Final print out the total cost of this month
Ideas:
1. Sort all the data first by name, then by time
2. Traverse, whether an is_out tag has been matched and printed (to determine if Total money should not be printed), and last to record the last state, if the last state is on-line and this time off-line, then {
Judge if you have ever agreed to a name (is_out)
Then start calculating time and money: Time and money do not have to be traversed in one minute and one minute. First make the number of days on and hours equal to off, then subtract the extra hours, and finally consider the minutes
//min
money-=last.m*p[last.h]; //more subtraction, note that p[last.h]
money+=a[i].m*p[a[i].h]; //less plus, note that p[a[i].h]
}
3.The month's processing card in the string.weep
Add an integer to a string
#include<bits/stdc++.h> using namespace std; int main(){ string s=""; s+="0"; int a=3; s+=a+'0'; cout<<s<<endl; return 0; }
4.is_out is initialized by a different name, forgot.Sorry.
Final full score code:
#include<bits/stdc++.h> using namespace std; struct node{ string name; int d; int h; int m; string state; }a[1005]; bool cmp(node &x,node &y){ if(x.name==y.name){ if(x.d==y.d){ if(x.h==y.h){ return x.m<y.m; }else{ return x.h<y.h; } }else{ return x.d<y.d; } }else{ return x.name<y.name; } } int main() { double p[25]; double sum_p=0; for(int i=0;i<=23;i++){ cin>>p[i]; p[i]*=0.01; sum_p+=p[i]*60; } int n; int month; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i].name; scanf("%2d:%2d:%2d:%2d",&month,&a[i].d,&a[i].h,&a[i].m); cin>>a[i].state; } sort(a+1,a+1+n,cmp); /*for(int i=1;i<=n;i++){ cout<<a[i].name<<" "<<a[i].d<<" "<<a[i].h<<" "<<a[i].m<<" "<<a[i].state<<endl; }*/ node last; last.name=""; int is_out=0;//Point!Is there a matching and output double totel=0; for(int i=1;i<=n;i++){ if(i==1){ last.name=a[i].name; last.d=a[i].d; last.h=a[i].h; last.m=a[i].m; last.state=a[i].state; is_out=0; continue; } if(a[i].name!=last.name){ if(is_out) { //One person before settlement printf("Total amount: $%.2lf\n",totel); totel=0; } is_out=0; //This sentence causes the first and second test points to fail. Once the names are different, whether they have been printed or not, is_out To initialize }else{ //See if the status pairs are right, not right""; if(last.state=="on-line"&&a[i].state=="off-line"){ //computing time int t=a[i].d-last.d; int t1=t*24*60; int t2=(a[i].h-last.h)*60; int t3=(a[i].m-last.m); //Calculation bill,It doesn't take a minute or a minute to run, just find the rules double money=0; money+=t*sum_p; //hour if(a[i].h>last.h)//Ratio Size { for(int j=last.h;j<a[i].h;j++){ money+=p[j]*60; } } else{ for(int j=a[i].h;j<last.h;j++){ money-=p[j]*60; } } //Minute money-=last.m*p[last.h];//Subtract more, notice that p[last.h] money+=a[i].m*p[a[i].h];//Less plus, note that p[a[i].h] //If this person has not been exported if(is_out==0) { cout<<a[i].name<<" "; printf("%02d\n",month); is_out=1;//Matched and output } printf("%02d:%02d:%02d %02d:%02d:%02d ",last.d,last.h,last.m,a[i].d,a[i].h,a[i].m); printf("%d $%.2lf\n",t1+t2+t3,money); totel+=money; } } last.name=a[i].name; last.d=a[i].d; last.h=a[i].h; last.m=a[i].m; last.state=a[i].state; } if(is_out){//Output only on matching printf("Total amount: $%.2lf\n",totel); } return 0; }
My own test data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 4 aaa 01:01:22:30 off-line aaa 01:02:23:50 off-line aaa 01:03:22:30 on-line aaa 01:11:23:50 on-line 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 4 aaa 12:01:22:30 on-line aaa 12:02:23:50 off-line aaa 12:03:22:30 off-line aaa 12:11:23:50 off-line 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 aaa 01:01:00:30 on-line aaa 01:01:00:30 off-line 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10 4 CYJJ 01:01:07:00 off-line CYJJ 01:01:05:59 on-line CYJJ 01:01:05:00 on-line CYJJ 01:01:07:59 off-line 10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10 18 CYLL 01:01:06:01 on-line CYLL 01:01:07:00 off-line CYLL 01:01:08:03 on-line CYLL 01:01:08:09 off-line CYLL 01:01:08:09 on-line CYLL 01:02:00:01 off-line CYLL 01:28:15:41 on-line CYLL 01:29:02:24 on-line CYLL 01:30:23:59 off-line CYLL 01:30:24:59 off-line CYLL 01:30:25:00 off-line CYLL 01:30:25:25 off-line MQ 01:01:06:01 on-line MQ 01:02:03:04 on-line MQ 01:03:04:05 on-line MQ 01:03:04:06 off-line YF 01:02:03:04 on-line YF 01:02:03:05 on-line
Looking so comfortable!!!