码迷,mamicode.com
首页 > 其他好文 > 详细

1075. PAT Judge (25)

时间:2015-02-01 08:27:49      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

  1 #include <stdio.h>
  2 #include <algorithm>
  3 using namespace std;
  4 
  5 struct MyStruct
  6 {
  7     int grade[6];
  8     int Done[6];
  9     int Perfect;
 10     int sum;
 11     int ID;
 12     int num;
 13 };
 14 
 15 int cmp(MyStruct a,MyStruct b)
 16 {
 17     if(a.sum != b.sum ) return a.sum > b.sum;
 18     if(a.Perfect != b.Perfect) return a.Perfect > b.Perfect;
 19     return a.ID < b.ID;
 20 }
 21 
 22 MyStruct Student[10001];
 23 MyStruct SqueStu[10001];
 24 int main()
 25 {
 26     int StuNum,ProNum,SubNum;
 27     int ProValue[6];
 28     int i,j;
 29     while(scanf("%d %d %d",&StuNum,&ProNum,&SubNum)!=EOF)
 30     {
 31         for(i=1;i<=StuNum;i++)
 32         {
 33             for(j=1;j<=5;j++)
 34             {
 35                 Student[i].grade[j]=-1;
 36                 Student[i].Done[j]=0;
 37             }
 38             Student[i].Perfect=0;
 39         }
 40         getchar();
 41         for(i = 1;i<=ProNum;i++)
 42             scanf("%d",&ProValue[i]);
 43 
 44         for(i=1;i<=SubNum;i++)
 45         {
 46             getchar();
 47             int TemID,TemProID,TemGrade;
 48             scanf("%d %d %d",&TemID,&TemProID,&TemGrade);
 49             if(TemGrade == -1) TemGrade = 0;
 50             else Student[TemID].Done[TemProID] = 1;
 51             if(TemGrade>Student[TemID].grade[TemProID])
 52             {
 53                 Student[TemID].grade[TemProID]=TemGrade;
 54                 Student[TemID].ID = TemID; 
 55                 if(TemGrade == ProValue[TemProID]) Student[TemID].Perfect++;
 56             }
 57         }
 58 
 59         int SqueStuNum=0;
 60         for(i=1;i<=StuNum;i++)
 61         {
 62             int Temsum=0;
 63             int IfPrint = 0;
 64             for(j=1;j<=ProNum;j++)
 65             {
 66                 if(Student[i].Done[j])
 67                 {
 68                     IfPrint=1;
 69                     Temsum+=Student[i].grade[j];
 70                 }
 71             }
 72 
 73             if(IfPrint)
 74             {
 75                 Student[i].sum=Temsum;
 76                 SqueStu[SqueStuNum++]=Student[i];
 77             }
 78         }
 79 
 80 
 81         sort(SqueStu,SqueStu+SqueStuNum,cmp);
 82 
 83         int tag=-100;
 84         int cnt=0;
 85         int add=1;
 86         for(i = 0;i < SqueStuNum ;i++)
 87         {    
 88             if( SqueStu[i].sum != tag )
 89             {
 90                 tag = SqueStu[i].sum;
 91                 cnt+= add;
 92                 add=1;
 93             }
 94             else  ++add;
 95 
 96             printf("%d %05d %d",cnt,SqueStu[i].ID,SqueStu[i].sum);
 97 
 98             for(j= 1;j <= ProNum ;j++)
 99             {
100                 if(SqueStu[i].grade[j] == -1) printf(" -");
101                 else
102                 {
103                     printf(" %d",SqueStu[i].grade[j]);
104                 }
105             }
106             printf("\n");
107         }
108     }
109     return 0;
110 }

 

1075. PAT Judge (25)

标签:

原文地址:http://www.cnblogs.com/xiaoyesoso/p/4265172.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!