Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <string>
  4. #include <map>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int string_to_int(string a)
  11. {
  12.     reverse(a.begin(), a.end());
  13.     int d = 1;
  14.     int res = 0;
  15.     for(int i = 0; i < a.size(); i++)
  16.     {
  17.         res += (a[i] - '0') * d;
  18.         d *= 10;
  19.     }
  20.     return res;
  21. }
  22.  
  23.  
  24. double res_time(string a, int num)
  25. {
  26.     double minutes = string_to_int(a.substr(0, 2));
  27.     double seconds = (double)string_to_int(a.substr(3, 2)) + ((double)string_to_int(a.substr(6, 1)) / 10);
  28.     double res = minutes * 60 + seconds - num * 30;
  29.     return res;
  30. }
  31.  
  32. struct sman
  33. {
  34.     int time, start;
  35.     string name;
  36.     sman(): time(), start(), name(){}
  37.     sman(int _time, int _start, string _name): time(_time), start(_start), name(_name){}
  38. };
  39.  
  40. bool cmp (sman a, sman b)
  41. {
  42.     return a.time < b.time;
  43. }
  44.  
  45.  
  46.  
  47. int main()
  48. {
  49. #ifndef ONLINE_JUDGE
  50.     freopen("input.txt", "r", stdin);
  51.     freopen("output.txt", "w", stdout);
  52. #endif
  53.     int n;
  54.     cin >> n;
  55.     vector<sman> for_sort;
  56.     map<string, int> res;
  57.     map<int, string> finish;
  58.     for(int i = 0; i < n; i++)
  59.     {
  60.         string name;
  61.         cin >> name;
  62.         string time;
  63.         cin >> time;
  64.         int t = res_time(time, -i);
  65.         for_sort.push_back(sman(t, i, name));
  66.     }
  67.     sort(for_sort.begin(), for_sort.end(), cmp);
  68.     for(int i = 0; i < n; i++)
  69.     {
  70.         int b = for_sort[i].time - for_sort[i].start * 2 * 30;
  71.         finish[b] = for_sort[i].name;
  72.         if(finish.begin()->first == b)
  73.             res[finish[b]]++;
  74.     }
  75.     cout << res.size() << endl;
  76.     for(auto it = res.begin(); it != res.end(); it++)
  77.         cout << it->first << endl;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement