#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
struct Stu{
int id;
int partial[6];
int totalscore;
int perfect;
int rank;
int flag;
bool operator <(const Stu &b) const{
if(totalscore!=b.totalscore){
return totalscore>b.totalscore;
}
if(perfect!=b.perfect){
return perfect>b.perfect;
}
return id<b.id;
}
};
Stu stu[100008];
int full[6];
int n,k,m;
int main(){
int id,num,score;
//freopen("/Users/pantingting/Documents/code/data/input", "r", stdin);
memset(stu, 0, sizeof(stu));
scanf("%d%d%d",&n,&k,&m);
for (int i=1; i<=n; i++)
for (int j=1; j<=k; j++) {
stu[i].partial[j]=-2;
}
for (int i=1; i<=k; i++)
scanf("%d",&full[i]);
for (int i=0; i<m; i++) {
scanf("%d%d%d",&id,&num,&score);
stu[id].id=id;
if (stu[id].partial[num]<score) {//如果有重复提交则更新成绩为提交的最高分。
if (score>=0)
stu[id].flag=1;//代表曾经提交过,需要出现在排名中
if (score==full[num]) {//第一次满分,perfect++,往后若再满分不应该重复计数。
stu[id].perfect++;
}
stu[id].partial[num]=score;
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=k; j++) {
stu[i].totalscore+=stu[i].partial[j]<0?0:stu[i].partial[j];
}
}
sort(stu+1, stu+n+1);//给学生排序
stu[1].rank=1;
for (int i=2; i<=n; i++) {
if (stu[i].totalscore==stu[i-1].totalscore) {
stu[i].rank=stu[i-1].rank;
}
else
stu[i].rank=i;
}
for (int i=0; i<=n; i++) {
if (stu[i].flag==0) {//对于从未提交或者从未通过编译的学生不输出结果。
continue;
}
printf("%d %05d",stu[i].rank,stu[i].id);
printf(" %d",stu[i].totalscore);
for (int j=1; j<=k; j++) {
if (stu[i].partial[j]>=0) {
printf(" %d",stu[i].partial[j]);
}
if (stu[i].partial[j]==-2) {
printf(" -");
}
if (stu[i].partial[j]==-1) {
printf(" 0");
}
}
printf("\n");
}
return 0;
}
PAT 1075 PAT Ranking
最新推荐文章于 2020-04-27 21:40:02 发布