题目大意:关于acm竞赛排名的题目,对于参赛者首先按做出的题目排名,然后是罚时,最后是编号。
多关键字域排序问题。
#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
#include <algorithm>
using namespace std; struct Cont
{
int id, num, t_penalty;
int penalty[];
bool solved[], join;
bool operator < (const Cont & c) const
{
if (num != c.num) return num > c.num;
if (t_penalty != c.t_penalty) return t_penalty < c.t_penalty;
return id < c.id;
}
} cont[]; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int T;
scanf("%d", &T);
getchar();
char str[];
gets(str);
while (T--)
{
memset(cont, , sizeof(cont));
for (int i = ; i <= ; i++)
cont[i].id = i;
while (gets(str) && str[])
{
int c, p, time;
char ch;
sscanf(str, "%d%d%d", &c, &p, &time);
for (int i = strlen(str)-; i >= ; i++)
if (isupper(str[i]))
{
ch = str[i];
break;
}
cont[c].join = true;
if (ch == 'C')
{
if (!cont[c].solved[p])
{
cont[c].num++;
cont[c].penalty[p] += time;
cont[c].solved[p] = true;
}
}
else if (ch == 'I')
{
if (!cont[c].solved[p])
cont[c].penalty[p] += ;
}
}
for (int i = ; i <= ; i++)
for (int j = ; j <= ; j++)
if (cont[i].solved[j])
cont[i].t_penalty += cont[i].penalty[j];
sort(cont+, cont+);
for (int i = ; i <= ; i++)
if (cont[i].join)
printf("%d %d %d\n", cont[i].id, cont[i].num, cont[i].t_penalty);
if (T) printf("\n");
}
return ;
}
要注意的是,当一道题目正确提交后,以后对该题目的提交都对结果无影响。一直注意这点了,却忘了当一道题最终没有正确提交时,以前的错误提交是不计算罚时的,因为这个纠结了好长时间,WA的好惨...看别人代码时心里还在想“干嘛多次一举保存每个题的罚时?”,忽然就明白了,是我错了...