您的位置:首页 > 其它

PAT甲级 1016

2017-06-29 19:02 363 查看

Phone Bills

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

Sample Output:

CYJJ 01

01:05:59 01:07:00 61 12.10Totalamount:12.10

CYLL 01

01:06:01 01:08:03 122 24.4028:15:4128:16:05243.85

Total amount: 28.25aaa0102:00:0104:23:594318638.80

Total amount: $638.80

模拟题

#include <string.h>
#include <stdio.h>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

const int maxsize=1000+10;
struct node{
int month,time;
bool status;
node(int m,int d,int h,int mi,bool s):
month(m),time(d*24*60+h*60+mi),status(s){}
};
vector<node> vn[maxsize];
map<string,int> ms;   //#include<string>
int price[24];

bool getStatus(char status[]){
if(status[1]=='n')return true;
return false;
}
bool cmp(node a,node b){
return a.time<b.time;
}
int main(){
//freopen("./in","r",stdin);
char name[20+1];
int i;
int n;
for(i=0;i<24;i++)scanf("%d",price+i);
scanf("%d",&n);
string str;
map<string,int>::iterator mit;
int cur,pos=0;
int month,day,hour,minute;
char status[20];
for(i=0;i<n;i++){
scanf("%s",name);
str=string(name);
mit=ms.find(str);
if(mit!=ms.end()){
cur=(*mit).second;
}else{
cur=pos;
pos++;
ms.insert(make_pair(str,cur));
}
scanf("%d:%d:%d:%d %s",&month,&day,&hour,&minute,status);
node a(month,day,hour,minute,getStatus(status));
vn[cur].push_back(a);
}

bool flag,bflag;
int ftime,stime;
double toll,total_toll;
vector<node>::iterator it;
for(mit=ms.begin();mit!=ms.end();mit++){
pos=(*mit).second;
sort(vn[pos].begin(),vn[pos].end(),cmp);
bflag=false;
it=vn[pos].begin();
flag=true;
for(;it!=vn[pos].end();it++){
if(flag && (*it).status){
flag=false;
continue;
}
if(!flag && !(*it).status){
bflag=true;
flag=true;
break;
}
}
if(!bflag)continue;

strcpy(name,(*mit).first.c_str());
printf("%s",name);

it=vn[pos].begin();
printf(" %02d\n",(*it).month);
total_toll=0;

for(;it!=vn[pos].end();it++){
if(!flag && (*it).status){
ftime=(*it).time;
continue;
}
if(flag && (*it).status){
ftime=(*it).time;
flag=false;
continue;
}
if(!flag && !(*it).status){
stime=(*it).time;
printf("%02d:%02d:%02d ",ftime/(24*60),ftime%(24*60)/60,ftime%60);
printf("%02d:%02d:%02d %d ",stime/(24*60),stime%(24*60)/60,stime%60,stime-ftime);
toll=0;
if(ftime/60!=stime/60){
toll+=(double(ftime/60*60+60-ftime))*price[ftime/60%24]/100;
ftime=ftime/60*60+60;
}
while(ftime+60<stime){
toll+=60.0*price[ftime/60%24]/100;
ftime+=60;
}
toll+=(double(stime-ftime))*price[ftime/60%24]/100;
total_toll+=toll;
printf("$%.2lf\n",toll);
flag=true;
}
}
printf("Total amount: $%.2lf\n",total_toll);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PAT PAT甲级 模拟题