#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 10010;
struct PAT_Student{
int id; //考号
int score[6]; //每道题的分数
bool flag; //是否有能通过编译的提交
int all_score; //总分
int prefect_problem;//完美题解数
}stu[MAXN], temp;
int full[6];
int n, k, m;
bool cmp(PAT_Student a, PAT_Student b) {
if(a.all_score != b.all_score)
return a.all_score > b.all_score; //从总分大到小排列
else if(a.prefect_problem != b.prefect_problem)
return a.prefect_problem > b.prefect_problem; //完美AC的题目数从多到少排列
else
return a.id < b.id; //考号小的在前面,既有小到大
}
void init() { //初始化
for(int i = 1; i <= n; i++) {
stu[i].id = i; //stu[i]中,0000i即为考号
stu[i].all_score = 0; //刚开始,大家得总分为 0
stu[i].prefect_problem = 0; //完美AC数为0
stu[i].flag = false; //没有未通过编译的提交
memset(stu[i].score, -1, sizeof(stu[i].score));
}
}
int main(){
scanf("%d %d %d", &n, &k, &m);
init();
for(int i = 1; i <= k; i++){
scanf("%d", &full[i]);
}
int user_id, problem_id, partial_score_obtained;
for(int i = 0; i < m; i++){
scanf("%d %d %d", &user_id, &problem_id, &partial_score_obtained);
// 若不是编译错误,则该考生有能通过编译的提交
if( partial_score_obtained != -1){
stu[user_id].flag = true;
}
// 某题第一次编译错误,分值记为0分,便于输出
if( partial_score_obtained == -1 && stu[user_id].score[problem_id] == -1){
stu[user_id].score[problem_id] = 0;
}
// 题第一次获得满分,则完美AC数加1
if( partial_score_obtained == full[problem_id] && stu[user_id].score[problem_id] < full[problem_id]){
stu[user_id].prefect_problem++;
}
// 某题获得更高分值,则覆盖
if( partial_score_obtained > stu[user_id].score[problem_id]){
stu[user_id].score[problem_id] = partial_score_obtained;
}
}
// 计算总分
for(int i = 1; i <= n; i++){
for(int j = 1; j <= k; j++){
if(stu[i].score[j] != -1){
stu[i].all_score += stu[i].score[j];
}
}
}
// 排序
sort(stu + 1, stu + n + 1, cmp);
// 当前排名
int r = 1;
for(int i = 1; i <= n && stu[i].flag == true; i++){
// 当前考生分数低于前一位考生分数时,则排名为在该考生之前的总考生数
if(i > 1 && stu[i].all_score != stu[i - 1].all_score){
r = i;
}
printf("%d %05d %d", r, stu[i].id, stu[i].all_score);
for(int j = 1; j <= k; j++){
if(stu[i].score[j] == -1){// 没有提交过
printf(" -");
}else{
printf(" %d", stu[i].score[j]);
}
}
printf("\n");
}
return 0;
}
原文地址:https://www.cnblogs.com/zjsaipplp/p/10425247.html
时间: 2024-10-09 01:06:35