Contest Scoreboard
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
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.
Subsequent test cases are separated with a single blank line.
Output
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.
Separate output for different cases with a single blank line.
Sample Input
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
Source: University of Waterloo Local Contest 1998.06.06
问题链接:UVA10258 Contest Scoreboard
问题简述:(略)
问题分析:
ACM比赛得分滚动榜问题。简单题,需要用到排序算法函数sort()。
需要注意输入输出格式以及空行的处理。
程序说明:(略)
参考链接:(略)
题记:输入输出格式需要了然于心!
AC的C++语言程序(UVA)如下:
/* UVA10258 Contest Scoreboard */
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 100;
const int P = 9;
int status[N + 1][P + 1];
int tindex[N + 1];
struct Record {
int team, cnt, time;
} record[N + 1];
bool cmp( Record a, Record b )
{
return a.cnt != b.cnt ? a.cnt > b.cnt : (a.time != b.time ? a.time < b.time : a.team < b.team);
}
char buf[128];
int main()
{
int t;
scanf("%d",&t);
getchar();
for(int i = 1; i <= t; i++) {
memset(record, 0, sizeof(record));
memset(status,0,sizeof(status));
memset(tindex, -1, sizeof(tindex));
int cnt=0, team, problem, time;
char L;
if(i == 1)
getchar();
while(gets(buf) != NULL && buf[0]) {
sscanf(buf, "%d %d %d %c", &team, &problem, &time, &L);
if(tindex[team] == -1) {
tindex[team] = cnt;
cnt++;
}
int k = tindex[team];
record[k].team = team;
if(status[k][problem] != -1) { // 已经AC的题不再处理
if(L == 'C') {
record[k].time += status[k][problem] * 20 + time;
record[k].cnt++;
status[k][problem] = -1;
} else if(L == 'I')
status[k][problem]++; // 未AC次数统计
}
}
sort(record, record + cnt, cmp);
for(int j=0; j<cnt; j++)
printf("%d %d %d\n", record[j].team, record[j].cnt, record[j].time);
if(i != t) printf("\n");
}
return 0;
}
AC的C++语言程序(ZOJ)如下:
/* ZOJ1837 Contest Scoreboard */
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 100;
const int P = 9;
int status[N + 1][P + 1];
int tindex[N + 1];
struct Record {
int team, cnt, time;
} record[N + 1];
bool cmp( Record a, Record b )
{
return a.cnt != b.cnt ? a.cnt > b.cnt : (a.time != b.time ? a.time < b.time : a.team < b.team);
}
char buf[128];
int main()
{
int caseno = 0;
char *ret;
do {
memset(record, 0, sizeof(record));
memset(status,0,sizeof(status));
memset(tindex, -1, sizeof(tindex));
int cnt=0, team, problem, time;
char L;
while((ret = gets(buf)) != NULL && buf[0]) {
sscanf(buf, "%d %d %d %c", &team, &problem, &time, &L);
if(tindex[team] == -1) {
tindex[team] = cnt;
cnt++;
}
int k = tindex[team];
record[k].team = team;
if(status[k][problem] != -1) { // 已经AC的题不再处理
if(L == 'C') {
record[k].time += status[k][problem] * 20 + time;
record[k].cnt++;
status[k][problem] = -1;
} else if(L == 'I')
status[k][problem]++; // 未AC次数统计
}
}
if(cnt > 0) {
if(++caseno > 1)
printf("\n");
sort(record, record + cnt, cmp);
for(int i=0; i<cnt; i++)
printf("%d %d %d\n", record[i].team, record[i].cnt, record[i].time);
}
} while(ret != NULL);
return 0;
}