# Contest Scoreboard

Time limit: 3.000 seconds

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 orE. 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


WA了一天，也没有找出错误。后来才知道是输入的时候没处理好，getchar()把不该吸收的回车吸收了。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

struct contestant {
int id; //队伍好
int penalty; //罚时
int cnt[10]; //每道题错误的次数
int solved[10]; //每道题的解决状态
int submit; //是否有提交记录
int problem; //AC的题目总数
}a[105];

bool comp(contestant a1, contestant a2) {
if(a1.problem != a2.problem)
return a1.problem > a2.problem;
if(a1.penalty != a2.penalty)
return a1.penalty < a2.penalty;
return a1.id < a2.id;
}

void Init() {
for(int i = 0; i < 105; i++) {
a[i].id = i;
a[i].penalty = a[i].problem = a[i].submit = 0;
memset(a[i].solved, 0, sizeof(a[i].solved));
memset(a[i].cnt, 0, sizeof(a[i].cnt));
}
}

int main()
{
int T, i, contest, time, pro, cas;
char ch, str[100];
scanf("%d",&T);
getchar();
int tmp = T;
for(cas = 1; cas <= T; cas++) {
if(cas == 1) //这里没处理好，WA了一天
getchar();
Init();
while(gets(str) != NULL && strcmp(str, "")) {
contest = pro = time = 0;
int len = strlen(str), s = 0;
for(i = 0; i < len - 1; i++) {
if(str[i] >= '0' && str[i] <= '9')
s = s * 10 + str[i] - '0';
else {
if(!contest) contest = s;
else if(contest && !pro) pro = s;
else if(contest && pro) time = s;
s = 0;
}
}
ch = str[len - 1];
a[contest].submit = 1;
if(ch == 'C' && !a[contest].solved[pro]) {
a[contest].problem++;
a[contest].penalty += (time + a[contest].cnt[pro] * 20);
a[contest].solved[pro] = 1;
}
else if(ch == 'I' && !a[contest].solved[pro]) {
a[contest].cnt[pro]++;
}
}
sort(a, a+105, comp);
if(cas > 1) printf("\n");
for(i = 0; i < 105; i++)
if(a[i].submit)
printf("%d %d %d\n", a[i].id, a[i].problem, a[i].penalty);
}
return 0;
}