problem

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

tip

  • 考察对STL库的熟悉情况的模拟题。

answer

#include<bits/stdc++.h>
using namespace std;
#define Max 1010
#define INF 0x3f3f3f3f
#define fi first
#define se second int rate[25], N; typedef struct {
float bill;
int minutes;
string begin, end;
}Call; typedef struct{
string time, tip, name;
}Time; typedef struct {
vector<Time> temp;
vector<Call> calls;
float sum;
}Data; Data D[1010];
map<string, Data> M;
map<string, Data>::iterator IT; int month[12] = {0, 31};
bool OnOff(string tip){
return tip.size() == 7 ? true : false;
} int TranTime(string t) {
int day, hour, minute;
day = (t[3]-'0')*10 + t[4]-'0';
hour = (t[6]-'0')*10 + t[7]-'0';
minute = (t[9]-'0')*10 + t[10] -'0';
return (day-1)*24*60 + hour*60 + minute;
} float CalBill(string t){
int oneDay = 0;
int sum = 0;
for(int i = 0; i < 24; i++){
oneDay += rate[i]*60;
}
int day, hour, minute;
day = (t[3]-'0')*10 + t[4]-'0';
hour = (t[6]-'0')*10 + t[7]-'0';
minute = (t[9]-'0')*10 + t[10] -'0'; sum += day*oneDay;
for(int i = 0; i < hour; i++)
{
sum += rate[i]*60;
}
sum += rate[hour]*minute; return (float)sum/100.0;
} bool Comp(Time a, Time b){
return a.time < b.time;
} int main (){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
for(int i = 0; i < 24; i++){
cin>>rate[i];
}
cin>>N;
for(int i = 0; i < N; i++) {
string name, time, tip;
cin>>name>>time>>tip;
Time t;
t.name = name;
t.time = time;
t.tip = tip;
M[t.name].temp.push_back(t);
}
for(IT = M.begin(); IT != M.end(); IT++){
sort(IT->second.temp.begin(), IT->second.temp.end(), Comp);
vector<Time> a = IT->se.temp;
stack <Time> sta;
Call call;
// cout<<IT->first<<" "<< a[0].time.substr(0,2)<<endl;
for(int i = 0; i < IT->se.temp.size(); i++){
if(OnOff(a[i].tip)){
sta.push(a[i]);
}else{
if(sta.empty()) continue;
call.begin = sta.top().time;
call.end = a[i].time;
call.minutes = TranTime(call.end) - TranTime(call.begin);
call.bill = CalBill(call.end) - CalBill(call.begin);
// cout<<call.begin.substr(3,10)<<" "<<call.end.substr(3, 10)<<" "<<call.minutes<<" $"<<fixed<<setprecision(2)<<call.bill<<endl;
IT->se.calls.push_back(call);
IT->second.sum += call.bill;
while(!sta.empty()) sta.pop();
}
}
// cout<<"Total amount: $"<<fixed<<setprecision(2)<<IT->se.sum<<endl;
}
for(IT = M.begin(); IT != M.end(); IT++){
vector<Time> a = IT->se.temp;
if(IT->se.calls.size() == 0) continue;
cout<<IT->first<<" "<< a[0].time.substr(0,2)<<endl;
for(int i = 0; i < IT->se.calls.size(); i++){
Call call = IT->se.calls[i];
cout<<call.begin.substr(3,10)<<" "<<call.end.substr(3, 10)<<" "<<call.minutes<<" $"<<fixed<<setprecision(2)<<call.bill<<endl;
}
cout<<"Total amount: $"<<fixed<<setprecision(2)<<IT->se.sum<<endl;
}
return 0;
}

exprience

  • 模拟题,小心配对错误,与无配对的情况。即是边界条件的考虑。

1016 Phone Bills (25)(25 point(s))的更多相关文章

  1. A1016 Phone Bills (25)(25 分)

    A1016 Phone Bills (25)(25 分) A long-distance telephone company charges its customers by the followin ...

  2. MySQL5.7.25(解压版)Windows下详细的安装过程

    大家好,我是浅墨竹染,以下是MySQL5.7.25(解压版)Windows下详细的安装过程 1.首先下载MySQL 推荐去官网上下载MySQL,如果不想找,那么下面就是: Windows32位地址:点 ...

  3. PAT 甲级 1006 Sign In and Sign Out (25)(25 分)

    1006 Sign In and Sign Out (25)(25 分) At the beginning of every day, the first person who signs in th ...

  4. 【PAT】1020 Tree Traversals (25)(25 分)

    1020 Tree Traversals (25)(25 分) Suppose that all the keys in a binary tree are distinct positive int ...

  5. 【PAT】1052 Linked List Sorting (25)(25 分)

    1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...

  6. 【PAT】1060 Are They Equal (25)(25 分)

    1060 Are They Equal (25)(25 分) If a machine can save only 3 significant digits, the float numbers 12 ...

  7. 【PAT】1032 Sharing (25)(25 分)

    1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...

  8. 【PAT】1015 德才论 (25)(25 分)

    1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得 ...

  9. 1003 Emergency (25)(25 point(s))

    problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...

  10. 1002 A+B for Polynomials (25)(25 point(s))

    problem 1002 A+B for Polynomials (25)(25 point(s)) This time, you are supposed to find A+B where A a ...

随机推荐

  1. SQL查找数据库中所有没有主键的数据表脚本

    --SQL查找数据库中所有没有主键的数据表脚本 --运行脚本后在消息中可能会显示下面现象中的一种:--(1)数据库中所有数据表都有主键(则证明所有数据表都有主键)--(2)当前数据表[数据表名]没有主 ...

  2. markdown小记(语法+markdownpad)

    一.有道云笔记markdown语法小记 1.目录[TOC] 2.标题# 一级标题## 二级标题...###### 六级标题 3.项目列表有序列表: 1. 1. (显示为i.) 2. 3. - (显示为 ...

  3. 15、BigDecimal类简介

    BigDecimal类概述 由于在运算的时候,float类型和double很容易丢失精度,在金融.银行等对数值精度要求非常高的领域里面,就不能使用float或double了,为了能精确的表示.计算浮点 ...

  4. shell脚本-监控及邮件提醒

    首先写一个邮件提醒python文件 #!/usr/bin/python # -*- coding: UTF-8 -*- import sys import smtplib import email.m ...

  5. Macaca(一) - 环境配置

    Macaca是阿里提供的一套自动化测试框架,目前已开源. 花了两三个小时研究了一下Macaca的实现原理.因为很好奇它与appium.selenium有啥区别. 实现原理本质上与selenium的we ...

  6. 【总结】2017年当下最值得你关注的前端开发框架,不知道你就OUT了!

    近几年随着 jQuery.Ext 以及 CSS3 的发展,以 Bootstrap 为代表的前端开发框架如雨后春笋般挤入视野,可谓应接不暇. 在这篇分享中,我将总结2017年当下最值得你关注的前端开发框 ...

  7. WeX5入门之欢乐捕鱼打包

    一.下载欢乐捕鱼的素材包 https://files.cnblogs.com/files/wordblog/%E7%B4%A0%E6%9D%90.zip 二.把欢乐捕鱼素材放入项目中 并启动tomca ...

  8. spring-boot-通用mapper

    数据源依赖 druid官方文档:https://github.com/alibaba/druid/wiki/常见问题 <dependency> <groupId>mysql&l ...

  9. Linux(Centos )的网络内核参数优化来提高服务器并发处理能力【转】

    简介 提高服务器性能有很多方法,比如划分图片服务器,主从数据库服务器,和网站服务器在服务器.但是硬件资源额定有限的情况下,最大的压榨服务器的性能,提高服务器的并发处理能力,是很多运维技术人员思考的问题 ...

  10. python 元组分组并排序

    # -*- coding: utf-8 -*- # @Time : 2018/8/31 14:32 # @Author : cxa # @File : glomtest.py # @Software: ...