Look for the Winner! (AOJ 1609) by ynu_a
Contest: 3394    RunID: 2247700    Status: Wrong Answer    Date: Sun Apr 09 16:05:15 JST 2017


#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int array[30] = {0};
    int n;
    int top = 0;
    int topalpha = 0;
    int next = 0;
    int nextalpha = 0;
    cin >> n;
    char temp;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        temp = temp - 65;
        array[temp]++;

        //top sagashi
        for (int j = 0; j < 30; j++)
        {
            if (top < array[j])
            {
                top = array[j];
                topalpha = j;
            }
        }

        //2nd sagashi
        for (int j = 0; j < 30; j++)
        {
            if (next < array[j] && j != topalpha)
            {
                next = array[j];
                nextalpha = j;
            }
        }
        int amari = n - i - 1;
        cout << i << " " << top << " " << next << " " << amari << endl;
        if (top <= next + amari)
        {
            //mada wakaran
            //cout<<i<<" "<<top<<" "<<next<<" "<<amari<<endl;
            continue;
        }
        else
        {
            //win top or tie
            if (top == next)
            {
                cout << "TIE" << endl;
                cout<<"hogehoge"<<endl;
                return 0;
            }
            else
            {
                printf("%c ", 65 + topalpha);
                printf("%d\n", i + 1);
                return 0;
            }
        }
    }
    printf("TIE\n");
    return 0;
}