#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=10010;
struct node
{
int id;
int total;
int score[6];
int solve;
int rank;
int at;
}stu[maxn];
int n,k,m;
int full[6];
int cmp(node a,node b)
{
if(a.total!=b.total)
return a.total>b.total;
else if(a.solve!=b.solve)
return a.solve>b.solve;
else
return a.id<b.id;
}
int main()
{
int id,num,grade;
//freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&k,&m);
for(int i=1;i<=k;i++)
scanf("%d",&full[i]);
for(int i=1;i<=n;i++)
{
stu[i].id=i;
stu[i].total=0;
stu[i].solve=0;
stu[i].at=0;
for(int j=0;j<6;j++)
stu[i].score[j]=-1;
}
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&id,&num,&grade);
if(grade!=-1&&stu[id].score[num]<grade)
stu[id].score[num]=grade;
else if(grade==-1&&stu[id].score[num]==-1)
stu[id].score[num]=0;
if(grade!=-1)
stu[id].at=1;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)
{
if(stu[i].score[j]==full[j])
stu[i].solve++;
if(stu[i].score[j]!=-1)
stu[i].total+=stu[i].score[j];
}
}
sort(stu+1,stu+n+1,cmp);
stu[1].rank=1;
for(int i=2;i<=n;i++)
{
if(stu[i].total==stu[i-1].total)
stu[i].rank=stu[i-1].rank;
else
stu[i].rank=i;
}
for(int i=1;i<=n;i++)
{
if(stu[i].at)
{
printf("%d %05d %d",stu[i].rank,stu[i].id,stu[i].total);
for(int j=1;j<=k;j++)
{
if(stu[i].score[j]!=-1)
printf(" %d",stu[i].score[j]);
else
printf(" -");
}
printf("\n");
}
}
return 0;
}
PAT1075(排序)
最新推荐文章于 2023-06-27 14:24:33 发布