Advertisement
Goga21

Untitled

Apr 3rd, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | Source Code | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool cmp(pair<int, int> first, pair<int, int> second){
  6.     if(first.first == second.first){
  7.         return first.second > second.second;
  8.     }else{
  9.         return first.first < second.first;
  10.     }
  11. }
  12.  
  13. int main(){
  14.     int n;
  15.     string s;
  16.     cin >> n;
  17.     getline(cin, s);
  18.     vector<unordered_map<string, int>> words(n);
  19.     for(int i = 0; i < n; ++i){
  20.         getline(cin, s);
  21.         stringstream Word_;
  22.         Word_ << s;
  23.         string a;
  24.         while(Word_ >> a){
  25.             ++words[i][a];
  26.         }
  27.     }
  28.     int t;
  29.     cin >> t;
  30.     getline(cin, s);
  31.     for(int i = 0; i < t; ++i){
  32.         vector<pair<int, int>> rel(n);
  33.         set<string> request;
  34.         getline(cin, s);
  35.         stringstream Word_;
  36.         Word_ << s;
  37.         string a;
  38.         while(Word_ >> a){
  39.             request.insert(a);
  40.         }
  41.         for(int j = 0; j < n; ++j){
  42.             for(const auto& x : request){
  43.                 rel[j].first += words[j][x];
  44.             }
  45.             rel[j].second = j + 1;
  46.         }
  47.         sort(rel.rbegin(), rel.rend(), cmp);
  48.         for(int j = 0; j < rel.size() && j < 5; j++){
  49.             if(rel[j].first!= 0) cout << rel[j].second << ' ';
  50.         }
  51.         cout << '\n';
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement