ZJU PAT 1012

 1 #include <stdio.h>
2 #include <string.h>
3 #define MAX_NUM 0x7fffffff
4 typedef struct Stu{
5 char ID[10];
6 double score[4];
7 int best_rank;
8 int best_course;
9 }Stu;
10 Stu stu[1000000];
11 int N,M;
12 char map[]={'C','M','E','A'};
13 int main()
14 {
15 int i;
16 scanf("%d%d",&N,&M);
17 for(i=0;i<N;i++){
18 scanf("%s%lf%lf%lf",&stu[i].ID,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
19
20 stu[i].score[3]=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3;
21 }
22 int rank[4]={1,1,1,1};
23 for(i=0;i<N;i++){
24 int rank[4]={1,1,1,1};
25 int j,k;
26 for(j=0;j<N;j++){
27 for(k=0;k<4;k++){
28 if(i!=j&&stu[j].score[k]>stu[i].score[k])
29 rank[k]++;
30 }
31 }
32 int best_rank=MAX_NUM;
33 int best_course=MAX_NUM;
34 for(j=0;j<4;j++){
35 if(rank[j]<best_rank){
36 best_rank=rank[j];
37 best_course=j;
38 }
39 else if(rank[j]==best_rank){
40 if(j==3||j<best_course){
41 best_course=j;
42 }
43 }
44 }
45 stu[i].best_rank=best_rank;
46 stu[i].best_course=best_course;
47 }
48 for(i=0;i<M;i++){
49 char search[10];
50 scanf("%s",&search);
51 int j=0;
52 for(;j<N;j++){
53 if(strcmp(stu[j].ID,search)==0){
54 printf("%d %c\n",stu[j].best_rank,map[stu[j].best_course]);
55 break;
56 }
57 }
58 if(j==N)
59 printf("N/A\n");
60 }
61 }


http://pat.zju.edu.cn/contests/pat-practise/1012

原文地址:https://www.cnblogs.com/yangce/p/2203298.html