Algorithm
problem Link : https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1199
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
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
using namespace std;
int main(){
int t;
string in;
int id, qId, time;
char L;
scanf("%d\n",&t);
while(t--){
unordered_map < int, int> penalty_map;
unordered_map<int, unordered_set<int>> solved_map;
unordered_map < int, vector<int>> accumulate_map;
while(getline(cin,in)){
if(in.empty()) break;
istringstream iss(in);
iss >> id >> qId >> time >> L;
if(!solved_map.count(id)){
solved_map[id] = unordered_set < int>();
penalty_map[id] = 0;
accumulate_map[id] = vector<int>(10,0);
}
if(solved_map[id].count(qId)) continue;
if(L == 'C'){
penalty_map[id] += time;
penalty_map[id] += accumulate_map[id][qId];
solved_map[id].insert(qId);
} else if(L == 'I'){
accumulate_map[id][qId] += 20;
}
}
vector<tuple < int,int,int>> res;
for(auto p : penalty_map){
res.push_back(make_tuple(p.first, solved_map[p.first].size(), p.second));
}
sort(res.begin(),res.end(>,[](tuple < int,int,int>& a, tuple<int,int,int>& b){
if(get<1>(a) != get<1>(b)) return get<1>(a) > get<1>(b);
if(get<2>(a) != get<2>(b)) return get<2>(a) < get<2>(b);
return get < 0>(a) < get<0>(b);
});
for(auto& t : res){
printf("%d %d %d\n",get < 0>(t), get<1>(t), get<2>(t));
}
if(t) cout << endl;
}
}
Copy The Code &
Try With Live Editor
Input
1 2 10 I
3 1 11 C
1 2 19 R
1 2 21 C
1 1 25 C
Output
3 1 11
Demonstration
UVA Online Judge solution - 10258 - Contest Scoreboard - UVA Online Judge solution in C,C++,java