Skip to content

Commit 9e9502b

Browse files
committed
Done 1002
1 parent d32724b commit 9e9502b

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

1000/1002.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <iostream>
2+
#include <cstring>
3+
#define N 100
4+
using namespace std;
5+
6+
struct Train {
7+
int id;
8+
char *location;
9+
char *time;
10+
};
11+
12+
void strupper(char *);
13+
14+
15+
int main() {
16+
int n;
17+
cin >> n;
18+
Train trains[n];
19+
for (int i = 0; i < n; ++i) {
20+
trains[i].location = new char[N];
21+
trains[i].time = new char[N];
22+
cin >> trains[i].id >> trains[i].location >> trains[i].time;
23+
strupper(trains[i].location);
24+
}
25+
26+
char location[N];
27+
cin >> location;
28+
strupper(location);
29+
30+
int index = -1;
31+
char min_time[N];
32+
for (int i = 0; i < n; ++i) {
33+
if (strcmp(trains[i].location, location) == 0 && index == -1 || strcmp(trains[i].time, min_time) < 0) {
34+
strcpy(min_time, trains[i].time);
35+
index = i;
36+
} else {
37+
delete[] trains[i].location;
38+
delete[] trains[i].time;
39+
}
40+
}
41+
42+
if (index == -1) {
43+
cout << "Impossible";
44+
} else {
45+
cout << trains[index].id << '_' << trains[index].location << '_' << trains[index].time;
46+
delete[] trains[index].location;
47+
delete[] trains[index].time;
48+
}
49+
50+
return 0;
51+
}
52+
53+
void strupper(char *s) {
54+
for (size_t i = 0, l = strlen(s); i < l; ++i) {
55+
s[i] = (char) toupper(s[i]);
56+
}
57+
}

0 commit comments

Comments
 (0)