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: 28ms
Memory: 1560kB
In contest: 1258

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct s{
	char id[5];
	int g1,g2,g3,sum;
}s[10010];
int cmp(const void *a,const void *b){
	if(((struct s*)a)->sum!=((struct s*)b)->sum)
		return ((struct s*)a)->sum<((struct s*)b)->sum;
	else if(((struct s*)a)->g1!=((struct s*)b)->g1)
		return ((struct s*)a)->g1<((struct s*)b)->g1;
	else if(((struct s*)a)->g2!=((struct s*)b)->g2)
		return ((struct s*)a)->g2<((struct s*)b)->g2;
	else if(((struct s*)a)->g3!=((struct s*)b)->g3)
		return ((struct s*)a)->g3<((struct s*)b)->g3;
	else
		return strcmp(((struct s*)a)->id,((struct s*)b)->id);
}
int main() 
{
	char a[100];
	int n,q,x,y,i,j,b,sum[3]={0},c;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s%d%d%d",s[i].id,&s[i].g1,&s[i].g2,&s[i].g3);
		sum[0]+=s[i].g1;
		sum[1]+=s[i].g2;
		sum[2]+=s[i].g3;
		s[i].sum=s[i].g1+s[i].g2+s[i].g3;
	}
	scanf("%d",&q);
	for(i=1;i<=q;i++){
		scanf("%d",&b);
		if(b==1){
			scanf("%s",a);
			for(j=0;j<n;j++)
				if(strcmp(a,s[j].id)==0){
					printf("Query #%d: 1 %s\n%d %d %d %d\n",i,a,s[j].sum,s[j].g1,s[j].g2,s[j].g3);
					break;
				}
		}
		else if(b==2){
			scanf("%d",&c);
			printf("Query #%d: 2 %d\n%.2lf\n",i,c,1.0*sum[c-1]/n);
		}
	}
	qsort(s,n,sizeof(struct s),cmp);
	for(i=0;i<n;i++)
		printf("%s %d %d %d %d\n",s[i].id,s[i].sum,s[i].g1,s[i].g2,s[i].g3);
}