Advertisement
Guest User

Untitled

a guest
Dec 17th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. #include <algorithm>
  9.  
  10. using namespace std;
  11.  
  12. struct team
  13. {
  14.         string s;
  15.         int n;
  16. };
  17.  
  18. bool comp (const team &a, const team &b)
  19. {
  20.         if (a.n != b.n)
  21.                 return a.n > b.n;
  22.  
  23.         return a.s < b.s;
  24. }
  25.  
  26. int main()
  27. {
  28.     freopen("closedcup.in", "r", stdin);
  29.     freopen("closedcup.out", "w", stdout);
  30.    
  31.     map < string, vector <string> > teams;
  32.     map < string, vector <string> > :: iterator team_it;
  33.     map <string, int> :: iterator pl;
  34.    
  35.     int i, n, j, k;
  36.     char ch, s[2000];
  37.     string ts, curr_team;
  38.  
  39.     scanf("%d\n", &n);
  40.  
  41.     for (i = 0; i < n; i++)
  42.     {
  43.         ts.clear();
  44.  
  45.         gets(s);
  46.  
  47.         ch = s[0];
  48.         k = 0;
  49.  
  50.         do
  51.         {
  52.             ts.push_back(ch);
  53.             ch = s[++k];
  54.         }
  55.         while (ch != ':');
  56.  
  57.         curr_team = ts;
  58.  
  59.         vector <string> *vs = &teams[curr_team];
  60.  
  61.         k++;
  62.  
  63.         while (ch != '.')
  64.         {
  65.             ts.clear();
  66.  
  67.             while (ch != ',' && ch != '.')
  68.             {
  69.                 ch = s[++k];
  70.  
  71.                 if (ch != ',' && ch != '.')
  72.                     ts.push_back(ch);
  73.             }
  74.  
  75.             vs->push_back(ts);
  76.  
  77.             if (ch == '.')
  78.                 break;
  79.  
  80.             if (ch == ',')
  81.                 ch = s[++k];
  82.         }
  83.     }
  84.  
  85.     for (team_it = teams.begin(); team_it != teams.end(); team_it++)
  86.     {
  87.         vector <team> tt;
  88.         team ttt;
  89.  
  90.         if (team_it != teams.begin())
  91.             printf("\n");
  92.  
  93.         printf("%s:\n", team_it->first.c_str());
  94.  
  95.         sort(team_it->second.begin(), team_it->second.end());
  96.  
  97.         for (i = 0; i < team_it->second.size(); i++)
  98.         {
  99.             ttt.s = team_it->second[i];
  100.  
  101.             j = 1;
  102.  
  103.  
  104.             while (i+j < team_it->second.size() && team_it->second[i] == team_it->second[i+j])
  105.                 j++;
  106.  
  107.             ttt.n = j;
  108.  
  109.             i += j - 1;
  110.  
  111.             tt.push_back(ttt);
  112.         }          
  113.            
  114.         sort(tt.begin(), tt.end(), comp);
  115.  
  116.         for (i = 0; i < tt.size(); i++)
  117.             printf("    %s, %d.\n", tt[i].s.c_str(), tt[i].n);
  118.     }
  119.  
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement