Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool cmp(pair<int, int> first, pair<int, int> second){
- if(first.first == second.first){
- return first.second > second.second;
- }else{
- return first.first < second.first;
- }
- }
- int main(){
- int n;
- string s;
- cin >> n;
- getline(cin, s);
- vector<unordered_map<string, int>> words(n);
- for(int i = 0; i < n; ++i){
- getline(cin, s);
- stringstream Word_;
- Word_ << s;
- string a;
- while(Word_ >> a){
- ++words[i][a];
- }
- }
- int t;
- cin >> t;
- getline(cin, s);
- for(int i = 0; i < t; ++i){
- vector<pair<int, int>> rel(n);
- set<string> request;
- getline(cin, s);
- stringstream Word_;
- Word_ << s;
- string a;
- while(Word_ >> a){
- request.insert(a);
- }
- for(int j = 0; j < n; ++j){
- for(const auto& x : request){
- rel[j].first += words[j][x];
- }
- rel[j].second = j + 1;
- }
- sort(rel.rbegin(), rel.rend(), cmp);
- for(int j = 0; j < rel.size() && j < 5; j++){
- if(rel[j].first!= 0) cout << rel[j].second << ' ';
- }
- cout << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement