标签:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct Student
{
int ID;
int score[6];
int perfect;
int sum;
int rank;
}S[10066];
int p[6]; //1-5存题号1-5小题的分值
bool cmp(Student a,Student b)
{
if(a.sum!=b.sum)
return a.sum>b.sum;
else if(a.perfect!=b.perfect)
return a.perfect>b.perfect;
else
return a.ID<b.ID;
}
int main()
{
memset(S,0,sizeof(S));
int n,k,m; //n个人,k道题,提交量m
scanf("%d%d%d",&n,&k,&m);
for(int i=1 ; i<=k ; ++i)
scanf("%d",&p[i]); //存入分值
for(int i=0 ; i<m ; ++i)
{
int name,score,testnum;
scanf("%d %d %d",&name, &testnum, &score);
S[name].score[testnum]=score;
if(score==p[testnum]) //此题满分
++S[name].perfect;
if(score!=-1)
S[name].sum+=score; //更新总分
}
sort(S,S+n,cmp);
S[0].rank=1;
for(int i=1 ; i<n ; ++i) //生成排名
{
if(S[i].score==S[i-1].score) //【skill】分数不同,排名为i+1;分数相同,排名还是前一个,不变
S[i].rank=S[i].rank;
else
S[i].rank=i+1;
}
for(int i=0 ; i<n ; ++i) //输出
{
if(S[i].sum!=0) //该同学存在有效成绩
{
printf("%d %05d",S[i].rank, S[i].ID);
for(int j=1 ; j<=k ; ++j)
{
if(S[i].score[j]!=-1) //不是-1输出成绩
printf(" %d",S[i].score[j]);
else //是-1,输出“-”
printf(" -");
}
}
printf("\n");
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/Evence/p/4308306.html