Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <map>
- #include <stdio.h>
- #include <vector>
- #include <cctype>
- using namespace std;
- struct Point
- {
- int h ,m ;
- Point(int a,int b)
- : h(a),m(b){}
- Point()
- {}
- };
- struct Point2
- {
- string game;
- int h ,m ;
- Point2(string a,int b,int c)
- : game(a),h(b),m(c){}
- Point2()
- {}
- };
- bool mycmp(Point2 a , Point2 b)
- {
- if(a.h!=b.h)
- return (a.h>b.h);
- else if(a.m!=b.m)
- return (a.m>b.m);
- else
- {
- return lexicographical_compare(a.game.begin(),a.game.end(),b.game.begin(),b.game.end());
- }
- }
- int main()
- {
- map<string,Point> games;
- map<string,Point> ::iterator it;
- int N, h,m;
- string game_name;
- cin >> N;
- while(N--)
- {
- cin >> game_name;
- scanf(" %d:%d",&h,&m);
- it = games.find(game_name);
- if (it==games.end())
- games[game_name] = Point(h,m);
- else games[game_name] =Point((*it).second.h + h + (((*it).second.m + m )/60),((*it).second.m + m) % 60);
- }
- vector<Point2> out;
- for(it = games.begin();it!=games.end();it++)
- out.push_back(Point2((*it).first,(*it).second.h,(*it).second.m));
- sort(out.begin(),out.end(),mycmp);
- int max = out.size();
- for(int i = 0; i < max;i++)
- {
- cout << out[i].game << " ";
- if (out[i].h<10) cout << "0";
- cout << out[i].h << ":";
- if (out[i].m<10) cout << "0";
- cout << out[i].m << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment