Tuesday, March 15, 2011

UVa_10258_Contest_Scoreboard.cpp

Problem Links:

uva10258,

Problem:

Question B - Contest Scoreboard

Think the contest score boards are wrong? Here's your chance to come up with the right rankings.
Contestants are ranked first by the number of problems solved (the more the better), then by decreasing amounts of penalty time. If two or more contestants are tied in both problems solved and penalty time, they are displayed in order of increasing team numbers. A problem is considered solved by a contestant if any of the submissions for that problem was judged correct. Penalty time is computed as the number of minutes it took for the first correct submission for a problem to be received plus 20 minutes for each incorrect submission received prior to the correct solution. Unsolved problems incur no time penalties.

Input:

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Input consists of a snapshot of the judging queue, containing entries from some or all of contestants 1 through 100 solving problems 1 through 9. Each line of input will consist of three numbers and a letter in the format
contestant problem time L
where L can be C, I, R, U or E. These stand for Correct, Incorrect, clarification Request, Unjudged and Erroneous submission. The last three cases do not affect scoring.
Lines of input are in the order in which submissions were received.

Output:

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Output will consist of a scoreboard sorted as previously described. Each line of output will contain a contestant number, the number of problems solved by the contestant and the time penalty accumulated by the contestant. Since not all of contestants 1-100 are actually participating, display only the contestants that have made a submission.

Sample Input:

1

1 2 10 I
3 1 11 C
1 2 19 R
1 2 21 C
1 1 25 C

Sample Output:

1 2 66
3 1 11

Solution:

Object sorting, convert string to integer and char.

Source Code:

//Tue Mar 15 16:19:03 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class Contestant
{
public:
    int contestantID;
    vector<bool> correct;
    vector<int> penalty;
    bool participate;

    Contestant(int id, bool p)
    {
        contestantID = id;
        participate = p;
        for (int i = 1; i <= 9; i++)
        {
            correct.push_back(false);
            penalty.push_back(0);
        }
    }

    static bool cmp(const Contestant &A, const Contestant &B)
    {
        int count1 = 0;
        int sum1 = 0;
        for (int i = 0; i < A.correct.size(); i++)
        {
            if (A.correct[i] == true)
            {
                count1++;
                sum1 += A.penalty[i];
            }
        }
        int count2 = 0;
        int sum2 = 0;
        for (int i = 0; i < B.correct.size(); i++)
        {
            if (B.correct[i] == true)
            {
                count2++;
                sum2 += B.penalty[i];
            }
        }
        if (count1 > count2) return true;
        if (count1 == count2 && sum1 < sum2) return true;
        if (count1 == count2 && sum1 == sum2 && A.contestantID < B.contestantID) return true;
        return false;
    }
};

void initialize(vector<Contestant> &cont)
{
    for (int i = 0; i <= 100; i++)
    {
        cont.push_back(Contestant(i, false));
    }
}

void solve(vector<Contestant> &cont)
{
    string str;
    while (getline(cin, str) && str != "")
    {
        stringstream ss(str);
        int contestant, problem, time;
        char L;
        ss >> contestant >> problem >> time >> L;
        //cout << contestant << ", " << problem << ", " << time << ", " << L << endl;
        cont[contestant].participate = true;
        if (L != 'I' && L != 'C') continue;
        if (L == 'C')
        {
            if (cont[contestant].correct[problem] == false)
            {
                cont[contestant].penalty[problem] += time;
                cont[contestant].correct[problem] = true;
            }
        }
            // L == 'I'
        else
        {
            if (cont[contestant].correct[problem] == false)
            {
                cont[contestant].penalty[problem] += 20;
            }
        }
    }
}

void print(vector<Contestant> cont)
{
std:
    sort(cont.begin(), cont.end(), Contestant::cmp);
    for (int i = 0; i < cont.size(); i++)
    {
        if (cont[i].participate == true)
        {
            int count = 0;
            int sum = 0;
            for (int j = 0; j < cont[i].correct.size(); j++)
            {
                if (cont[i].correct[j] == true)
                {
                    count++;
                    sum += cont[i].penalty[j];
                }
            }
            cout << cont[i].contestantID << " " << count << " " << sum << endl;
        }
    }
}

int main(int argc, char* argv[])
{
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    int T;
    cin >> T;
    getchar();
    getchar();
    for (int ncase = 1; ncase <= T; ncase++)
    {
        if (ncase > 1) cout << endl;
        vector<Contestant> cons;
        initialize(cons);
        solve(cons);
        print(cons);
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

No comments :