Advertisement
Guest User

Untitled

a guest
Jan 1st, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<sstream>
  4. #include<vector>
  5.  
  6. #pragma GCC optimize ("O3")
  7. using namespace std;
  8.  
  9. int convertToMinutes(int time)
  10. {
  11.     int min = time % 10;
  12.     time /= 10;
  13.     min += (time % 10) * 10;
  14.     time /= 10;
  15.     min += (time % 10) * 60;
  16.     time /= 10;
  17.     min += (time % 10) * 600;
  18.     return min;
  19. }
  20.  
  21. int main()
  22. {
  23.     // Tweaks for faster cin execution
  24.     std::cin.sync_with_stdio(false);
  25.     std::cin.tie(nullptr);
  26.  
  27.     vector<int> bus_arrival_times;
  28.  
  29.     int time;
  30.     string input_line;
  31.     getline(cin >> ws, input_line);
  32.  
  33.     istringstream input_stream(input_line);
  34.  
  35.     while (input_stream && (input_stream >> time))
  36.     {
  37.         bus_arrival_times.push_back(convertToMinutes(time));
  38.     }
  39.  
  40.     int train_time;
  41.  
  42.     cin >> ws >> train_time;
  43.  
  44.     train_time = convertToMinutes(train_time);
  45.  
  46.     int min_wait_time = 100000;
  47.     for (int min : bus_arrival_times)
  48.     {
  49.         if (train_time < min)
  50.         {
  51.             continue;
  52.         }
  53.  
  54.         if (train_time - min < min_wait_time)
  55.         {
  56.             min_wait_time = train_time - min;
  57.         }
  58.     }
  59.  
  60.     cout << min_wait_time << endl;
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement