-
Notifications
You must be signed in to change notification settings - Fork 0
/
1095.cpp
134 lines (118 loc) · 2.3 KB
/
1095.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef struct node
{
string plate;
int time;
string statue;
}node;
typedef struct elem
{
string plate;
int intime;
int outtime;
}elem;
node inputs[10010];
elem records[5005];
map<string, int> mCar;
int N, K;
bool less_than_node(const node &A, const node &B)
{
if (A.plate != B.plate)
{
return A.plate < B.plate;
}
else
{
return A.time < B.time;
}
}
bool less_than_elem(const elem &A, const elem &B)
{
return A.outtime < B.outtime;
}
int main()
{
int hh, mm, ss;
int query;
int num = 0;
int index = 0;
int count = 0;
int max_time = -1;
vector<string> results;
cin >> N >> K;
for (int i = 0; i != N; ++i)
{
cin >> inputs[i].plate;
scanf("%d:%d:%d", &hh, &mm, &ss);
inputs[i].time = hh*3600+mm*60+ss;
cin >> inputs[i].statue;
}
sort(inputs, inputs+N, less_than_node);
for (int i = 0; i < N-1; )
{
if ((inputs[i].plate == inputs[i+1].plate) && (inputs[i].statue[0] == 'i') && (inputs[i+1].statue[0] == 'o'))
{
records[num].plate = inputs[i].plate;
records[num].intime = inputs[i].time;
records[num].outtime = inputs[i+1].time;
mCar[records[num].plate] += records[num].outtime - records[num].intime;
++num;
i += 2;
}
else
{
++i;
}
}
sort(records, records+num, less_than_elem);
for (int i = 0; i != K; ++i)
{
scanf("%d:%d:%d", &hh, &mm, &ss);
query = hh*3600+mm*60+ss;
count = 0;
while (index < num && records[index].outtime <= query)
{
++index;
}
for (int j = index; j < num; ++j)
{
if (records[j].intime <= query)
{
++count;
}
}
printf("%d\n", count);
}
for (map<string, int>::iterator iter = mCar.begin(); iter != mCar.end(); ++iter)
{
if (iter->second > max_time)
{
max_time = iter->second;
}
}
for (map<string, int>::iterator iter = mCar.begin(); iter != mCar.end(); ++iter)
{
if (iter->second == max_time)
{
results.push_back(iter->first);
}
}
sort(results.begin(), results.end());
for (vector<string>::iterator iter = results.begin(); iter != results.end(); ++iter)
{
cout << *iter << " ";
}
hh = max_time/3600;
mm = (max_time-hh*3600)/60;
ss = max_time%60;
printf("%02d:%02d:%02d\n", hh, mm, ss);
system("pause");
return 0;
}