1075. PAT Judge (25)

来源:互联网 发布:mac磁盘越来越小 编辑:程序博客网 时间:2024/06/06 02:07
//分数相同按解决问题的数量#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct pat{  int problems[6];  int problems_flag;        int score;  int sloved;  int id;  int rank;}stu[10010];bool cmp(pat a, pat b){  if(a.score != b.score)    return a.score>b.score;  else if(a.sloved != b.sloved)    return a.sloved>b.sloved;  else    return a.id<b.id;}int main(){  int N=0,K=0,M=0;  int full_mark[6]={0},i=0,j=0;  int id=0,no=0,score=0;  scanf("%d%d%d",&N,&K,&M);  for(i=1; i<=N; i++)  {    stu[i].id = i;    stu[i].problems_flag = false;    memset(stu[i].problems,-1,sizeof(stu[i].problems));  }  i = 0;  while(i<K)  {    scanf("%d",&full_mark[i+1]);    i++;  }  j = 0;  while(j<M)  {    scanf("%d%d%d",&id,&no,&score);  if(score >=0 )                    //提交且编译通过  {    stu[id].problems_flag = true;  }  if(score == -1 && stu[id].problems[no] == -1)  {    stu[id].problems[no] = 0;  }    if(score>stu[id].problems[no])     //记录最高分    {      //获得满分,解决数量加1      if(stu[id].problems[no] != full_mark[no] && score == full_mark[no])        stu[id].sloved += 1;      //更新最高分      stu[id].problems[no] = score;    }    j++;  }  for(i=0; i<=N; i++)  {  for(j=1; j<=K; j++)    if(stu[i].problems[j] != -1)      stu[i].score += stu[i].problems[j];  }  sort(stu+1,stu+N+1,cmp);  stu[1].rank = 1;  for(j=2; j<=N; j++)  {    if(stu[j].score == stu[j-1].score)      stu[j].rank = stu[j-1].rank;    else      stu[j].rank = j;  }  for(j=1; j<=N; j++)  {    if(stu[j].problems_flag==true)    {      printf("%d %05d %d",stu[j].rank,stu[j].id,stu[j].score);      for(i=1; i<=K; i++)      {    if(stu[j].problems[i] == -1)          printf(" -");        else          printf(" %d",stu[j].problems[i]);      }      printf("\n");    }  }  return 0;}

0 0
原创粉丝点击