Click Here to go back to the homepage.

Election Solution:


#include <bits/stdc++.h>
using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    string line;
    getline(cin, line);
    int nPeople = stoi(line);
    vector<tuple<string, string, int>> candidates;
    for(int i = 0; i < nPeople; i++){
        string name, party;
        getline(cin, name);
        getline(cin, party);
        candidates.push_back({name, party, 0});
    }
    getline(cin, line);
    int votes = stoi(line);
    while(votes--){
        string vote;
        getline(cin, vote);
        for(auto &t: candidates){
            if(get<0>(t) == vote){
                get<2>(t) = get<2>(t) + 1;
                break;
            }
        }
    }
    int max = 0;
    bool tie = true;
    string winner;
    for(tuple<string, string, int> t:candidates){
        if(get<2>(t) == max){
            tie = true;
        } else if(get<2>(t) > max){
            tie = false;
            max = get<2>(t);
            winner = get<1>(t);
        }
    }
    if(tie){
        cout << "tie" << endl;
    } else {
        cout << winner << endl;
    }
    return 0;   
}