Start: Jan, 08, 2019 19:01:00
2018年秋季学期程序设计基础(C语言)期末考试
End: Jan, 08, 2019 21:46:00
Time elapsed:
Time remaining:

Problem_ID: G
Result: Accepted
Time: 823ms
Memory: 1368kB
In contest: 1258

#include<stdio.h>
#include<string.h>
#include<math.h>
struct student{
	char xh[10];
	int score[3];
	int sum;
}stu[10005],temp;
int main(){
	int x,y,i,j,t,T,k,z,m,n;
	double sum1=0,sum2=0,sum3=0;char a[10];
	scanf("%d",&n);
	for(i=0;i<n;i++){
	scanf("%s %d %d %d",stu[i].xh,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
	stu[i].sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
	sum1=sum1+stu[i].score[0];
	sum2=sum2+stu[i].score[1];
	sum3=sum3+stu[i].score[2];
	}
	scanf("%d",&m);
	z=1;
	while(m--){
	scanf("%d",&x);
	if(x==1){
	scanf("%s",a);
	for(i=0;i<n;i++){
	if(strcmp(a,stu[i].xh)==0){
		printf("Query #%d: 1 %s\n%d %d %d %d\n",z,stu[i].xh,stu[i].sum,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
		break;
	}
	}

	}
	else{
        scanf("%d",&y);
		if(y==1)
			printf("Query #%d: 2 1\n%.2f\n",z,sum1/n);
		else if(y==2)
			printf("Query #%d: 2 2\n%.2f\n",z,sum2/n);
		else
			printf("Query #%d: 2 3\n%.2f\n",z,sum3/n);
	}
	z++;
	}
	for(i=0;i<n;i++){
		for(j=0;j<n-i+1;j++){
			if(stu[j].sum<stu[j+1].sum){
			temp=stu[j];stu[j]=stu[j+1];stu[j+1]=temp;
			}
			else if(stu[j].sum==stu[j+1].sum){
			     if(stu[j].score[0]<stu[j+1].score[0]){
			      temp=stu[j];stu[j]=stu[j+1];stu[j+1]=temp;
			      }
				 else if(stu[j].score[0]==stu[j+1].score[0]){
			         if(stu[j].score[1]<stu[j+1].score[1]){
			           temp=stu[j];stu[j]=stu[j+1];stu[j+1]=temp;
			           }
					 else if(stu[j].score[1]==stu[j+1].score[1]){
			            if(stu[j].score[2]<stu[j+1].score[2]){
			           temp=stu[j];stu[j]=stu[j+1];stu[j+1]=temp;
			           }
						else if(stu[j].score[2]==stu[j+1].score[2]){
			                 if(strcmp(stu[j].xh,stu[j+1].xh)>0){
			                  temp=stu[j];stu[j]=stu[j+1];stu[j+1]=temp;
			                  }
			             }
			        }
			    }
			}
		}
	}
	for(i=0;i<n;i++){
	printf("%s %d %d %d %d\n",stu[i].xh,stu[i].sum,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
	}
return 0;
}