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的更多相关文章

  1. PAT甲级1095. Cars on Campus

    PAT甲级1095. Cars on Campus 题意: 浙江大学有6个校区和很多门.从每个门口,我们可以收集穿过大门的汽车的进/出时间和车牌号码.现在有了所有的信息,你应该在任何特定的时间点告诉在 ...

  2. PAT甲级——1095 Cars on Campus (排序、映射、字符串操作、题意理解)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93135047 1095 Cars on Campus (30 分 ...

  3. 【刷题-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 ...

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

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

  6. A1095. Cars on Campus

    Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...

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

  8. PAT_A1095#Cars on Campus

    Source: PAT A1095 Cars on Campus (30 分) Description: Zhejiang University has 8 campuses and a lot of ...

  9. pat 甲级 Cars on Campus (30)

    Cars on Campus (30) 时间限制 1000 ms 内存限制 65536 KB 代码长度限制 100 KB 判断程序 Standard  题目描述 Zhejiang University ...

随机推荐

  1. STM32---初学者用库函数好还是直接对寄存器操作比较好

    引用:http://blog.csdn.net/u010349006/article/details/416 首先,两个都是C语言.从51过渡过来的话,就先说寄存器操作.每个MCU都有自己的寄存器,5 ...

  2. 7.springboot+mybatis+redis整合

    选择生成的依赖 选择保存的工程路径 查询已经生成的依赖,并修改mysql的版本 <dependencies> <dependency> <groupId>org.s ...

  3. iOS开发系列-Shell脚本生成IPA

    概述 在公司开发到了测试阶段需要频繁打包交付给测试,看似简单的工作,重复的流程总是感觉不是那么好,我们可以借助苹果提供的编译指令编译项目. 自动化脚本编译打包IPA 常见的iOS项目就是基于xcode ...

  4. JS按比例缩放图片

    1.JS代码 <script type="text/javascript" language="javascript"> var flag = fa ...

  5. next() 与 nextLine() 区别

    next() 与 nextLine() 区别 next(): 1.一定要读取到有效字符后才可以结束输入. 2.对输入有效字符之前遇到的空白,next() 方法会自动将其去掉. 3.只有输入有效字符后才 ...

  6. Android开发 string.xml资源添加参数

    挖坑:参考:https://www.cnblogs.com/leelugen/p/6685905.html

  7. [转]spring入门(六)【springMVC中各数据源配置】

    在使用spring进行javaWeb开发的过程中,需要和数据库进行数据交换,为此要经常获取数据库连接,使用JDBC的方式获取数据库连接,使用完毕之后再释放连接,这种过程对系统资源的消耗无疑是很大的,这 ...

  8. c++ strlen() 函数

    { char *buf = new char[1024]; ZeroMemory(buf,1024) for(int i = 0; i < 1023; i++) { buf[i] = '5'; ...

  9. python截图+百度ocr(图片识别)+ 百度翻译

    一直想用python做一个截图并自动翻译的工具,恰好最近有时间就在网上找了资料,根据资料以及自己的理解做了一个简单的截图翻译工具.整理一下并把代码放在github给大家参考.界面用python自带的G ...

  10. MyBatis基础-CRUD

    一.mybatis  环境搭建步骤 第一步:创建 maven 工程第二步:导入坐标第三步:编写必要代码(实体类和持久层接口)第四步:编写 SqlMapConfig.xml第五步:编写映射配置文件第六步 ...