IARCS (BCCS Elections)



/* Question:
http://www.iarcs.org.in/inoi/contests/oct2004/Basic-1.php
Author : Tausiq */

#include <stdio.h>

int main ()
{
    int N, C;
    scanf ("%d %d", &C, &N);

    int array [10002];

    for ( int i = 1; i <= C; i++ )
        array &#91;i&#93; = 0;

    for ( int i = 1; i <= N; i++ ) {
        int choice;
        scanf ("%d", &choice);
        array &#91;choice&#93;++;
    }

    int max = 0;
    int index;

    for ( int i = 1; i <= C; i++ ) {
        if ( array &#91;i&#93; > max ) {
            max = array [i];
            index = i;
        }
    }

    array [index] = 0;

    int max_2nd = 0;

    for ( int i = 1; i <= C; i++ ) {
        if ( array &#91;i&#93; > max_2nd ) {
            max_2nd = array [i];
            index = i;
        }
    }

    array [index] = 0;

    int max_3rd = 0;

    for ( int i = 1; i <= C; i++ ) {
        if ( array &#91;i&#93; > max_3rd ) {
            max_3rd = array [i];
            index = i;
        }
    }
    printf ("%d\n", index);

    return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s