POJ 2643 Election

Problem Link: POJ Election

/**
  *  @Author: Pranta Sarker
  *
  **/


/**
  *  @Author: Pranta Sarker
  *
  **/


#include<iostream>
#include<cstring>
#include<map>
#include<string>
#include<vector>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define pfn(x , k) printf(k , x)
#define nl puts("")
#define psb push_back
#define mset(c,v) memset(c , v , sizeof c)
#define loop0(n) for(int i=0; i<n; i++)
#define loop1(n) for(int i=1; i<=n; i++)
#define mpair(x , y) make_pair(x , y)
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)
#define psb push_back
#define clr clear()

typedef unsigned long long ull;
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef vector<string>vs;
typedef map<int, int>mpii;
typedef map<string, int>mpsi;
typedef map<char, int>mpci;
typedef map<LL, LL>mpll;
typedef map<string, string>mpss;

const int mod = 1000007;
const int high = 1002;

mpss mp;
mpsi mark;

int main()
{
    fast;
    int N;
    mp.clear();
    mark.clear();
    string name , party;
    cin >> N;
    cin.ignore();
    while(N--)
    {
        getline(cin , name);
        getline(cin , party);
        mp[name] = party;
        //cout << name << " - > " << party << "\n";
        //cin.ignore();
    }

    int M , maxi = 0;
    string winningparty = "";
    bool tie = false;
    cin >> M;
    cin.ignore();
    while(M--)
    {
        getline(cin , name);

        mark[name]++;
    }

    mpsi::iterator itr;

    for(itr=mark.begin(); itr!=mark.end(); ++itr)
    {
        if(maxi < itr->second)
        {
            maxi = itr->second;
            string tmp = itr->first;
            winningparty = mp[tmp];
        }

        else if(maxi == itr->second)
        {
            tie = true;
        }
    }

    if(tie)
    {
        cout << "tie\n";
    }

    else
    {
        cout << winningparty << "\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number