UVa : 10258 (Contest Scoreboard)


// http://uva.onlinejudge.org/external/102/10258.html

//========================================
// Name        : UVa_10258.cpp
// Author      : Shahab
// Version     : Accepted
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//========================================

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <bitset>
#include <utility>
#include <set>
#define pi acos(-1.0)
#define N 1000000
using namespace std;

struct teams {
    int teamNumber;
	int solved [9 + 3];
	int penalty [9 + 3];
	bool submit;
} a [100 + 5];

void reset ()
{
	for ( int i = 0; i < 105; i++ ) {
	    a [i].teamNumber = i;
		memset (a [i].solved, 0, sizeof (a [i].solved));
		memset (a [i].penalty, 0, sizeof (a [i].penalty));
		a [i].submit = false;
	}
}

void calculateAll ()
{
    for ( int i = 1; i < 105; i++ ) {
        for ( int j = 1; j <= 9; j++ ) {
            if ( a [i].solved [j] ) {
                a [i].solved [10]++;
                a [i].penalty [10] += a [i].penalty [j];
            }
        }
	}
}

bool cmp (teams x, teams y)
{
	if ( x.solved [10] > y.solved [10] ) return true;
	if ( x.solved [10] == y.solved [10] && x.penalty [10] < y.penalty [10] ) return true;
	if ( x.solved [10] == y.solved [10] && x.penalty [10] == y.penalty [10] && x.teamNumber < y.teamNumber ) return true;
	return false;
}

int main() {
    //freopen ("input.txt", "r", stdin);
    //freopen ("out.txt", "w", stdout);

	int testCase;
	scanf ("%d", &testCase);
	getchar ();

    bool blank = false;
	char input [1000];

	gets (input);

	while ( testCase-- ) {
		reset ();

		while ( gets (input) && strlen (input) ) {
			int c, p, t;
			char l;

			sscanf (input, "%d %d %d %c",&c, &p, &t, &l );

			a [c].submit = true;

			if ( l == 'R' || l == 'U' || l == 'E' ) continue;

			if ( l == 'C' ) {
			    if ( !a [c].solved [p] ) {
                    a [c].solved [p] = 1;
                    a [c].penalty [p] += t;
			    }
			}
			else {
                if ( !a [c].solved [p] )
                    a [c].penalty [p] += 20;
			}
		}

		calculateAll ();

		sort (a, a + 105, cmp);

		if ( blank )
			printf ("\n");
		blank = true;

		for ( int i = 0; i <= 105; i++ ) {
			if ( a [i].submit )
				printf ("%d %d %d\n", a [i].teamNumber, a [i].solved [10], a [i].penalty [10]);
		}
	}

	return 0;
}
Advertisements

2 thoughts on “UVa : 10258 (Contest Scoreboard)

  1. Critical Input : 
    3
    
    1 5  9 I
    2 5 10 R
    3 7 12 U
    4 8 15 E
    9 3 20 C
    
    3 7 12 C
    3 9 22 C
    3 7 23 I
    
    100 9 100 C
    100 9 105 C
    
    output :
    9 1 20
    1 0 0
    2 0 0
    3 0 0
    4 0 0
    
    3 7 12 C
    3 9 22 C
    3 7 23 I
    
    100 1 100
    

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