Look for the Winner! (AOJ 1609) by ynu_a
Contest: 3394    RunID: 2247744    Status: Accepted    Date: Sun Apr 09 16:32:34 JST 2017


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

int main()
{
    while (true)
    {
    LABEL:
        int array[30] = {0};
        int n;
        int top = 0;
        int topalpha = 0;
        int next = 0;
        int nextalpha = 0;
        int amari = 0;
        cin >> n;
        if (n == 0)
        {
            return 0;
        }
        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;
                }
            }
            amari = n - i - 1;
            char hoge;
            //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;
                    for (int j = 0; j < amari; j++)
                    {
                        cin >> hoge;
                    }
                    goto LABEL;
                }
                else
                {
                    printf("%c ", 65 + topalpha);
                    printf("%d\n", i + 1);
                    for (int j = 0; j < amari; j++)
                    {
                        cin >> hoge;
                    }
                    goto LABEL;
                }
            }
        }
        printf("TIE\n");
    }
    return 0;
}