Untitled

 avatar
unknown
plain_text
4 months ago
1.3 kB
3
Indexable
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <string>

using namespace std;

int main() {
    int p;  // numărul de prieteni
    cin >> p;
    
    // Dicționar pentru prieteni și jocurile lor
    unordered_map<string, unordered_set<string>> friends_games;
    
    // Citim datele pentru fiecare prieten
    for (int i = 0; i < p; ++i) {
        string friend_name;
        int num_games;
        cin >> friend_name >> num_games;
        
        unordered_set<string> games;
        for (int j = 0; j < num_games; ++j) {
            string game;
            cin >> game;
            games.insert(game);
        }
        
        // Stocăm jocurile pentru prietenul curent
        friends_games[friend_name] = games;
    }
    
    // Citim jocul pe care dorim să-l jucăm
    string game_to_play;
    cin >> game_to_play;
    
    // Contorul prietenilor care au acest joc
    int count = 0;
    
    // Verificăm pentru fiecare prieten dacă au jocul dorit
    for (const auto& entry : friends_games) {
        const auto& games = entry.second;
        if (games.find(game_to_play) != games.end()) {
            ++count;
        }
    }
    
    // Afișăm rezultatul
    cout << count << endl;
    
    return 0;
}
Editor is loading...
Leave a Comment