はまやんはまやんはまやん

hamayanhamayan's blog

Football Match [CodeChef December Cook-Off 2017 A]

https://www.codechef.com/COOK89/problems/FBMT
N試合あり、勝ったチームが記録される。
どのチームが勝ったかを出力せよ。勝数が同数の場合は"Draw"とする。

解法

N=0の時は試合が無いので、勝数0vs0なので"Draw"
0

int N;
//---------------------------------------------------------------------------------------------------
string solve() {
    cin >> N;
 
    if (N == 0) return "Draw";
 
    map<string, int> cnt;
    rep(i, 0, N) {
        string s; cin >> s;
        cnt[s]++;
    }
 
    if (cnt.size() == 1) return cnt.begin()->first;
 
    auto ite = cnt.begin();
 
    auto p1 = *ite; ite++;
    auto p2 = *ite;
 
    if (p1.second == p2.second) return "Draw";
    if (p1.second > p2.second) return p1.first;
    return p2.first;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    int T; cin >> T;
    rep(t, 0, T) printf("%s\n", solve().c_str());
}