PAT甲级——A1095 Cars on Campus
Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information available, you are supposed to tell, at any specific time point, the number of cars parking on campus, and at the end of the day find the cars that have parked for the longest time period.
Input Specification:
Each input file contains one test case. Each case starts with two positive integers N (≤), the number of records, and K (≤) the number of queries. Then N lines follow, each gives a record in the format:
plate_number hh:mm:ss status
where plate_number
is a string of 7 English capital letters or 1-digit numbers; hh:mm:ss
represents the time point in a day by hour:minute:second, with the earliest time being 00:00:00
and the latest 23:59:59
; and status
is either in
or out
.
Note that all times will be within a single day. Each in
record is paired with the chronologically next record for the same car provided it is an out
record. Any in
records that are not paired with an out
record are ignored, as are out
records not paired with an in
record. It is guaranteed that at least one car is well paired in the input, and no car is both in
and out
at the same moment. Times are recorded using a 24-hour clock.
Then K lines of queries follow, each gives a time point in the format hh:mm:ss
. Note: the queries are given in ascending order of the times.
Output Specification:
For each query, output in a line the total number of cars parking on campus. The last line of output is supposed to give the plate number of the car that has parked for the longest time period, and the corresponding time length. If such a car is not unique, then output all of their plate numbers in a line in alphabetical order, separated by a space.
Sample Input:
16 7
JH007BD 18:00:01 in
ZD00001 11:30:08 out
DB8888A 13:00:00 out
ZA3Q625 23:59:50 out
ZA133CH 10:23:00 in
ZD00001 04:09:59 in
JH007BD 05:09:59 in
ZA3Q625 11:42:01 out
JH007BD 05:10:33 in
ZA3Q625 06:30:50 in
JH007BD 12:23:42 out
ZA3Q625 23:55:00 in
JH007BD 12:24:23 out
ZA133CH 17:11:22 out
JH007BD 18:07:01 out
DB8888A 06:30:50 in
05:10:00
06:30:50
11:00:00
12:23:42
14:00:00
18:00:00
23:59:00
Sample Output:
1
4
5
2
1
0
1
JH007BD ZD00001 07:20:09
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
using namespace std;
struct Node
{
string ID;
bool flag;//1是进,0是出
int time;
Node(string s, bool f, int t) :ID(s), flag(f), time(t) {}
};
vector<Node>Cars;
unordered_map<string, vector<Node>>map;//一辆车不止一个记录
vector<string>res;
int N, K, maxTime = ;
int main()
{
cin >> N >> K;
string ID, flag;
int h, m, s;
while (N--)
{
cin >> ID;
scanf("%d:%d:%d", &h, &m, &s);
cin >> flag;
map[ID].push_back(Node(ID, flag == "in", h * + m * + s));
}
for (auto ptr = map.begin(); ptr != map.end(); ++ptr)
{
sort(ptr->second.begin(), ptr->second.end(), [](Node a, Node b) {return a.time < b.time; });
int t = ;
for (int i = ; i < ptr->second.size()-; ++i)
{
if (ptr->second[i].flag == && ptr->second[i + ].flag == )//一进一出
{
Cars.push_back(ptr->second[i]);//记录合法时间
Cars.push_back(ptr->second[i + ]);//记录合法时间
t += ptr->second[i + ].time - ptr->second[i].time;//累加停车时间
}
}
if (t > maxTime)
{
maxTime = t;
res.clear();
res.push_back(ptr->first);
}
else if(t==maxTime)
res.push_back(ptr->first);
}
sort(Cars.begin(), Cars.end(), [](Node a, Node b) {return a.time < b.time; });
int num = , i = ;
while (K--)
{
scanf("%d:%d:%d", &h, &m, &s);
int time = h * + m * + s;
for (; i < Cars.size() && Cars[i].time <= time; ++i)
num += Cars[i].flag ? : -;//使用用-1表示该车开出去了
cout << num << endl;
}
sort(res.begin(), res.end());
for (auto v : res)
cout << v << " ";
printf("%02d:%02d:%02d\n", maxTime / , maxTime % / , maxTime % );
return ;
}
PAT甲级——A1095 Cars on Campus的更多相关文章
- PAT甲级1095. Cars on Campus
PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...
- PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93135047 1095 Cars on Campus (30 分 ...
- 【刷题-PAT】A1095 Cars on Campus (30 分)
1095 Cars on Campus (30 分) Zhejiang University has 8 campuses and a lot of gates. From each gate we ...
- A1095 Cars on Campus (30)(30 分)
A1095 Cars on Campus (30)(30 分) Zhejiang University has 6 campuses and a lot of gates. From each gat ...
- PAT A1095 Cars on Campus (30 分)——排序,时序,从头遍历会超时
Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out time ...
- A1095. Cars on Campus
Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...
- A1095 Cars on Campus (30 分)
Zhejiang University has 8 campuses and a lot of gates. From each gate we can collect the in/out time ...
- PAT_A1095#Cars on Campus
Source: PAT A1095 Cars on Campus (30 分) Description: Zhejiang University has 8 campuses and a lot of ...
- pat 甲级 Cars on Campus (30)
Cars on Campus (30) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard 题目描述 Zhejiang University ...
随机推荐
- 004-Java进制转换
整型数据共有4中进制形式 二进制(binary):以0b或者0B开头 十进制(decimal) 八进制(octal):以数字0开头 十六进制(hex):以0x或者0X开头 二进制数据包含原码反码和补码 ...
- iOS开发系列-支付宝支付
概述 开发中支付通常都会集成支付宝支付,下面讲解支付宝的整体流程. 集成支付宝支付的流程 签约 与支付签约,得到获取商户的ID(partner).账户ID(seller).私钥privateKey. ...
- JS对象 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置。
返回指定的字符串首次出现的位置 indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置. 语法 stringObject.indexOf(substring, startpos) 参 ...
- marktext常用快捷键使用说明
快捷键使用 功能 快捷键 备注 X级标题 ctrl+X X∈[1~6] 加粗 Ctrl+B 标题默认加粗 倾斜 Ctrl+I 插入表格 Ctrl+T 侧边文件信息显示 Ctrl+J 删除线 Ctrl ...
- php相关操作
array_unshift : 数组头部追加 用法如下: $arr = ['demo','dmoa']; array_unshift($arr,'demob'); //在$arr的前面追加demob ...
- Batch - C:\Progra~1是什么意思
就是那种DOS下的8.3的规范,可以这样写 C:\Progra~1也可以这样写全名字的 "C:\Program File",因为这个路径中的文件夹名有空格,要用两个英文输入法下的双 ...
- 计算几何,向量——cf995c
网上的题解直接用随机过的, 自己用模拟就模拟三个向量的和并就模拟不出来.. 以后再回头看看 #include<bits/stdc++.h> #include<cmath> us ...
- Delphi 实现窗体无标题栏有边框
1.在窗体的public区写下这一句: Procedure CreateParams(var Params :TCreateParams);override;2然后把光标停在这一行上,按下Ctrl+S ...
- 尚学python课程---14、python中级语法
尚学python课程---14.python中级语法 一.总结 一句话总结: var[1:5] 访问模式:比如字符串,比如列表元祖,字典等 del 删除模式:比如列表.元祖.字典 1.Python的N ...
- VS2010-MFC(字体和文本输出:CFont字体类)
转自:http://www.jizhuomi.com/software/239.html 字体简介 GDI(Graphics Device Interface),图形设备接口,是Windows提供的一 ...