Advertisement
kolioi

Games (JA3-Task-3-Games) C++

Jan 14th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. typedef struct team
  9. {
  10.     vector<string> vPlayerList;
  11.     int nWins;
  12.     team() : nWins(0) {}
  13. } Team;
  14.  
  15. int main()
  16. {
  17.     cin.sync_with_stdio(false);
  18.     cout.sync_with_stdio(false);
  19.  
  20.     int nTeams;
  21.     cin >> nTeams;
  22.  
  23.     map<string, Team> teamList;
  24.     for (int i = 0; i < nTeams; i++)
  25.     {
  26.         Team team;
  27.         string szTeamName;
  28.         int nTeamSize;
  29.         cin >> szTeamName >> nTeamSize;
  30.         team.vPlayerList.reserve(nTeamSize);
  31.         while (nTeamSize--)
  32.         {
  33.             string szPlayer;
  34.             cin >> szPlayer;
  35.             team.vPlayerList.push_back(szPlayer);
  36.         }
  37.         teamList[szTeamName] = team;
  38.     }
  39.  
  40.     int nGames;
  41.     cin >> nGames;
  42.  
  43.     for (int i = 0; i < nGames; i++)
  44.     {
  45.         string szTeamName;
  46.         cin >> szTeamName;
  47.         teamList[szTeamName].nWins++;
  48.     }
  49.  
  50.     map<string, int> mPlayerScores;
  51.     for (const auto& item : teamList)
  52.     {
  53.         for (const string& str : item.second.vPlayerList)
  54.         {
  55.                 mPlayerScores[str] += item.second.nWins;
  56.         }
  57.     }
  58.  
  59.     map<string, int>::iterator it = mPlayerScores.begin();
  60.     while (it != mPlayerScores.end())
  61.     {
  62.         cout << it->second << " ";
  63.         it++;
  64.     }
  65.  
  66.     cout << endl;
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement