Advertisement
Malinovsky239

Fast train

May 18th, 2011
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. string name, s, timer1, timer2, bestname;
  8. int h1, h2, m1, m2, all_time, result = int(1e9), n, cnt;
  9.  
  10. int main()
  11. {
  12.     freopen("input.txt", "r", stdin);
  13.     freopen("output.txt", "w", stdout);
  14.  
  15.     cin >> n;
  16.  
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         cnt = 0;
  20.         name = "";
  21.  
  22.         for (;;)
  23.         {
  24.             cin >> s;
  25.             name += s;
  26.  
  27.             for (int j = 0; j < s.size(); j++)
  28.                 if (s[j] == '"')
  29.                     cnt++;
  30.  
  31.             if (cnt == 2) break;
  32.             name += " ";
  33.         }
  34.  
  35.         cin >> timer1 >> timer2;
  36.  
  37.         sscanf(timer1.c_str(), "%d:%d ", &h1, &m1);
  38.         sscanf(timer2.c_str(), "%d:%d ", &h2, &m2);
  39.  
  40.         all_time = (h2 * 60 + m2) - (h1 * 60 + m1);
  41.         if (all_time <= 0) all_time += 24 * 60;
  42.  
  43.         if (all_time < result)
  44.         {
  45.             result = all_time;
  46.             bestname = name;
  47.         }
  48.     }
  49.  
  50.     cout << "The fastest train is " << bestname <<".\nIt's speed is " << int(650.0 / result * 60 + 0.5) << " km/h, approximately.";
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement