File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments