Guest User

Untitled

a guest
Jan 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <map>
  5. #include <stdio.h>
  6. #include <vector>
  7. #include <cctype>
  8.  
  9. using namespace std;
  10.  
  11. struct Point
  12. {
  13.     int h ,m ;
  14.     Point(int a,int b)
  15.         : h(a),m(b){}
  16.     Point()
  17.         {}
  18. };
  19.  
  20. struct Point2
  21. {
  22.     string game;
  23.     int h ,m ;
  24.     Point2(string a,int b,int c)
  25.         : game(a),h(b),m(c){}
  26.     Point2()
  27.         {}
  28. };
  29.  
  30. bool mycmp(Point2 a , Point2 b)
  31. {
  32.     if(a.h!=b.h)
  33.         return (a.h>b.h);
  34.     else if(a.m!=b.m)
  35.         return (a.m>b.m);
  36.         else
  37.         {
  38.             return lexicographical_compare(a.game.begin(),a.game.end(),b.game.begin(),b.game.end());
  39.         }
  40. }
  41.  
  42. int main()
  43. {
  44.     map<string,Point> games;
  45.     map<string,Point> ::iterator it;
  46.     int N, h,m;
  47.     string game_name;
  48.     cin >> N;
  49.     while(N--)
  50.     {
  51.         cin >> game_name;
  52.         scanf(" %d:%d",&h,&m);
  53.         it = games.find(game_name);
  54.         if (it==games.end())
  55.             games[game_name] = Point(h,m);
  56.         else games[game_name]  =Point((*it).second.h + h + (((*it).second.m + m )/60),((*it).second.m + m) % 60);
  57.     }
  58.    
  59.     vector<Point2> out;
  60.    
  61.     for(it = games.begin();it!=games.end();it++)
  62.         out.push_back(Point2((*it).first,(*it).second.h,(*it).second.m));
  63.    
  64.     sort(out.begin(),out.end(),mycmp);
  65.    
  66.     int max = out.size();
  67.     for(int i = 0; i < max;i++)
  68.         {
  69.             cout << out[i].game << " ";
  70.             if (out[i].h<10) cout << "0";
  71.             cout << out[i].h << ":";
  72.             if (out[i].m<10) cout << "0";
  73.             cout << out[i].m << endl;
  74.         }
  75.    
  76.     return 0;
  77. }
Add Comment
Please, Sign In to add comment