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: 1230ms
Memory: 1212kB
In contest: 1258

#include<stdio.h>
#include<string.h>
int main(){float a1=0,a2=0,a3=0;
struct{
	int gaoshu,xiandai,chengxu,total;
	char name[5];}a[10005],temp;
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %d %d %d",a[i].name,&a[i].gaoshu,&a[i].chengxu,&a[i].xiandai);a[i].total=a[i].chengxu+a[i].gaoshu+a[i].xiandai;
	}
for(i=0;i<n-1;i++){
	for(j=0;i<n-j-1;j++){
		if((a[j].total<a[j+1].total)||(a[j].total==a[j+1].total&&a[j].gaoshu<a[j+1].gaoshu)||(a[j].total==a[j+1].total&&a[j].gaoshu==a[j+1].gaoshu&&a[j].chengxu<a[j+1].chengxu)||(a[j].total==a[j+1].total&&a[j].gaoshu==a[j+1].gaoshu&&a[j].chengxu==a[j+1].chengxu&&a[j].xiandai<a[j+1].xiandai)||(a[j].total==a[j+1].total&&a[j].gaoshu==a[j+1].gaoshu&&a[j].chengxu==a[j+1].chengxu&&a[j].xiandai==a[j+1].xiandai&&strcmp(a[j].name,a[j+1].name)>0)){
			temp=a[j];
			a[j]=a[j+1];
			a[j+1]=temp;
		}}}

for(i=0;i<n;i++){a1+=a[i].gaoshu;a2+=a[i].chengxu;a3+=a[i].xiandai;
}a1/=n;a2/=n;a3/=n;
int q,p;scanf("%d",&q);int shit=1;
while(q--){
	scanf("%d",&p);
	if(p==1){char w[5];scanf("%s",w);printf("Query #%d: 1 %s\n",shit,w);
	for(i=0;i<n;i++){
		if(strcmp(w,a[i].name)==0){
			printf("%d %d %d %d\n",a[i].total,a[i].gaoshu,a[i].chengxu,a[i].xiandai);
		}
	}
	
	}
	else if(p==2){scanf("%d",&p);
	printf("Query #%d: 2 %d\n",shit,p);
	if(p==1)printf("%.2f\n",a1);
	if(p==2)printf("%.2f\n",a2);
	if(p==3)printf("%.2f\n",a3);
	}shit++;	}
	for(i=0;i<n;i++){
		printf("%s %d %d %d %d\n",a[i].name,a[i].total,a[i].gaoshu,a[i].chengxu,a[i].xiandai);
	}}