您的位置:首页 > 其它

PAT(甲级) 1016. Phone Bills (25)

2018-02-05 21:13 453 查看
1016. Phone Bills (25)


时间限制

400 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

CHEN, Yue

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



更多源码:https://github.com/Azure-Sky-L/PAT

给出 0~24 小时,每小时内的话费单价:分钟 / 美分

一些客户一个月内的通话记录,求每个客户的话费账单(按名字字典序打印客户账单)

sort 按名字、天、时、分排好序,根据相邻的名字、on-line/off-line 处理输出

#include<cstdio>
#include<map>
#include<algorithm>
#include<iostream>
using namespace std;
int a[25];
struct node{
string s;
char c[25];
int m,d,h,f;
}st[1010];
bool cmp(node i,node j){
if(i.s == j.s)
if(i.d == j.d)
if(i.h == j.h) return i.f < j.f;
else return i.h < j.h;
else return i.d < j.d;
else return i.s < j.s;
}
double mm(node i,node j){
double m = 0;
while(i.d < j.d || i.h < j.h || i.f < j.f){
m += a[i.h];
i.f++;
if(i.f == 60) i.f = 0,i.h++;
if(i.h == 24) i.h = 0,i.d++;
}
return m / 100;
}
int main()
{
for(int i = 0; i < 24; i++)
scanf("%d",&a[i]);
int q,ans,ok,sy;
double sum;
scanf("%d",&q);
for(int i = 1; i <= q; i++)
cin >> st[i].s,scanf("%d:%d:%d:%d %s",&st[i].m,&st[i].d,&st[i].h,&st[i].f,st[i].c);
sort(st + 1,st + 1 + q,cmp);
for(int i = 1; i <= q; i++){
if(st[i].s != st[i - 1].s) sum = ok = sy = 0;
if(st[i].c[1] == 'n') ok = 1;
if(st[i].c[1]== 'f' && ok && st[i].s == st[i - 1].s){
ok = 0;
if(!sy){
cout << st[i].s;
printf(" %02d\n",st[i].m);
sy = 1;
}
printf("%02d:%02d:%02d ",st[i - 1].d,st[i - 1].h,st[i - 1].f);
printf("%02d:%02d:%02d ",st[i].d,st[i].h,st[i].f);
ans = st[i].f - st[i - 1].f + 60 * (st[i].h - st[i - 1].h) + 60 * 24 * (st[i].d - st[i - 1].d);
printf("%d ",ans);
double cut = mm(st[i - 1],st[i]);
printf("$%.2f\n",cut);
sum += cut;
}
if(st[i].s != st[i + 1].s && sum != 0)
printf("Total amount: $%.2f\n",sum);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PAT甲级1016