Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int busCount;
- cin >> busCount;
- string bus, train;
- string* busTimes = new string[busCount];
- for (int i = 0; i < busCount; i++) {
- cin >> busTimes[i];
- }
- cin >> train;
- int index = 0,
- diffTime = 0,
- minDiff = 2147483647,
- trainTime = stoi(train.substr(0, 2)) * 60 + stoi(train.substr(2));
- for (int i = 0; i < busCount; i++) {
- diffTime = trainTime - (stoi(busTimes[i].substr(0, 2)) * 60 + stoi(busTimes[i].substr(2)));
- if (diffTime < 0) {
- index = i;
- break;
- }
- else if (abs(diffTime) < minDiff) {
- minDiff = abs(diffTime);
- index = i + 1;
- }
- }
- cout << index << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement