Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <map>
- #include <algorithm>
- using namespace std;
- struct team
- {
- string s;
- int n;
- };
- bool comp (const team &a, const team &b)
- {
- if (a.n != b.n)
- return a.n > b.n;
- return a.s < b.s;
- }
- int main()
- {
- freopen("closedcup.in", "r", stdin);
- freopen("closedcup.out", "w", stdout);
- map < string, vector <string> > teams;
- map < string, vector <string> > :: iterator team_it;
- map <string, int> :: iterator pl;
- int i, n, j, k;
- char ch, s[2000];
- string ts, curr_team;
- scanf("%d\n", &n);
- for (i = 0; i < n; i++)
- {
- ts.clear();
- gets(s);
- ch = s[0];
- k = 0;
- do
- {
- ts.push_back(ch);
- ch = s[++k];
- }
- while (ch != ':');
- curr_team = ts;
- vector <string> *vs = &teams[curr_team];
- k++;
- while (ch != '.')
- {
- ts.clear();
- while (ch != ',' && ch != '.')
- {
- ch = s[++k];
- if (ch != ',' && ch != '.')
- ts.push_back(ch);
- }
- vs->push_back(ts);
- if (ch == '.')
- break;
- if (ch == ',')
- ch = s[++k];
- }
- }
- for (team_it = teams.begin(); team_it != teams.end(); team_it++)
- {
- vector <team> tt;
- team ttt;
- if (team_it != teams.begin())
- printf("\n");
- printf("%s:\n", team_it->first.c_str());
- sort(team_it->second.begin(), team_it->second.end());
- for (i = 0; i < team_it->second.size(); i++)
- {
- ttt.s = team_it->second[i];
- j = 1;
- while (i+j < team_it->second.size() && team_it->second[i] == team_it->second[i+j])
- j++;
- ttt.n = j;
- i += j - 1;
- tt.push_back(ttt);
- }
- sort(tt.begin(), tt.end(), comp);
- for (i = 0; i < tt.size(); i++)
- printf(" %s, %d.\n", tt[i].s.c_str(), tt[i].n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement