#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
struct User{
int id;
int score[6];
int total;
int rk,perfect;
};
bool cmp(User a,User b)
{
if(a.total!=b.total) return a.total>b.total;
else if(a.perfect!=b.perfect) return a.perfect>b.perfect;
else return a.id<b.id;
}
int main()
{
int n,k,m;
cin>>n>>k>>m;
User user[n+1];
int full[k+1]={0};
int i,j;
for(i=1;i<=k;i++) cin>>full[i];
for(i=1;i<=n;i++){
for(j=1;j<=k;j++){
user[i].score[j]=-2; //未提交过答案的题目得分为-2
}
user[i].perfect=0;
user[i].id=i;
} //初始化
int id,problem,score;
for(i=0;i<m;i++){
scanf("%d%d%d",&id,&problem,&score);
if(score>full[problem]) continue; //无效数据
if(user[id].score[problem]<score){
user[id].score[problem]=score;
}
} //input
vector<User> vi; //未提供有效提交的不计入ranklist
for(i=1;i<=n;i++){
int total=0;
bool flag=false;
for(j=1;j<=k;j++){
if(user[i].score[j]>=0){
total+=user[i].score[j];
flag=true; //提供了有效提交
if(user[i].score[j]==full[j])
user[i].perfect++; //full mark
}
}
user[i].total=total;
if(flag==true) vi.push_back(user[i]);
} //计算总分并筛选出合格样本
sort(vi.begin(),vi.end(),cmp);
int num=vi.size();
for(i=0;i<num;i++){
if(i!=0&&vi[i].total==vi[i-1].total) vi[i].rk=vi[i-1].rk;
else vi[i].rk=i+1;
printf("%d %05d %d ",vi[i].rk,vi[i].id,vi[i].total);
for(j=1;j<=k;j++){ //输出各题成绩
if(vi[i].score[j]==-2) printf("-");
else if(vi[i].score[j]==-1) printf("0");
else printf("%d",vi[i].score[j]);
if(j!=k) printf(" ");
}
printf("\n");
}
return 0;
}
PAT A 1075 PAT Judge
最新推荐文章于 2021-10-27 22:25:46 发布