Advertisement
Spocoman

01. School Administrator

Feb 17th, 2024
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. bool is_find(vector<string>& v, string el) {
  11.     return find(v.begin(), v.end(), el) != v.end();
  12. }
  13.  
  14. int main() {
  15.     map<int, vector<string>> kidParticipants;
  16.  
  17.     string participant;
  18.     cin >> participant;
  19.  
  20.     while (participant != "END") {
  21.         int room;
  22.         cin >> room;
  23.         kidParticipants[room].push_back(participant);
  24.  
  25.         cin >> participant;
  26.     }
  27.  
  28.     cin >> participant;
  29.  
  30.     while (participant != "END") {
  31.         vector<int> rooms;
  32.         for (auto& k : kidParticipants) {
  33.             if (is_find(k.second, participant)) {
  34.                 rooms.push_back(k.first);
  35.             }
  36.         }
  37.  
  38.         cout << participant << ':';
  39.         if (rooms.empty()) {
  40.             cout << " Not found!\n";
  41.         }
  42.         else {
  43.             for (int i = 0; i < rooms.size(); i++) {
  44.                 cout << ' ' << rooms[i];
  45.             }
  46.             cout << endl;
  47.         }
  48.  
  49.         cin >> participant;
  50.     }
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement