前言
在最近整理大学前两年学的内容时,突然发现了这个数据结构程序,主要目标是实时观测一个校园停车场的状态。现发布在这里,希望可以给学习的同袍们一点帮助。
题目要求
8-1 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:

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 <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef struct info* INFO; //INFO is a struct pointer which points to a struct storing information about cars
struct info
{
vector<int> in; //vector in contains time the car came in
vector<int> out; //vector in contains time the car went out
int total_time; //total_time calculates the total time the car parked in the canpus
};
map<string, INFO> Map; //Map connect the plate number and corresponding struct pointer INFO
vector<int> query; //query stores the time of queries (transfer the time to seconds so it's INT)
int n, K; //n is the total number of records and K is the number of queries
//this function process the input
void ReadData()
{
cin >> n >> K;
string s1, s2; //s1 and s2 are just temporary strings
int hour, minute, second;
for (int i = 0; i < n; i

最低0.47元/天 解锁文章
808

被折叠的 条评论
为什么被折叠?



