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: 26ms
Memory: 1476kB
In contest: 1258

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?b:a)
struct  stdd
{
	int id;
	int gs;
	int cx;
	int xd;
	int sum;
} stu[10010];

int cmp(struct  stdd *a,struct  stdd *b)
{
	if(b->sum!=a->sum)
	return b->sum-a->sum;
	else if(b->gs!=a->gs)
	return b->gs-a->gs;
	else if(b->cx!=a->cx)
	return b->cx-a->cx;
	else if(b->xd!=a->xd)
	return b->xd-a->xd;
	else if(b->id!=a->id)
	return a->id-b->id;
}
int main()
{
	int n;
	double aver[4]={0};
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d%d%d",&stu[i].id,&stu[i].gs,&stu[i].cx,&stu[i].xd);
		stu[i].sum=stu[i].gs+stu[i].cx+stu[i].xd;
		aver[1]+=stu[i].gs;
		aver[2]+=stu[i].cx;
		aver[3]+=stu[i].xd;
	}
	qsort(stu,n,sizeof(struct  stdd),cmp);
	int q;
	scanf("%d",&q);
	for(int j=1;j<=q;j++)
	{
		int qq,nn;
		scanf("%d %d",&qq,&nn);
		if(qq==1)
		{
			for(int i=0;i<n;i++)
			{
				if(nn==stu[i].id)
				{
					printf("Query #%d: %d %05d\n",j,qq,nn);
					printf("%d %d %d %d\n",stu[i].sum,stu[i].gs,stu[i].cx,stu[i].xd);
					break;
				}			
			}			
		}
		else
		{
			printf("Query #%d: %d %d\n",j,qq,nn);
			printf("%.2lf\n",aver[nn]/n);
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("%05d %d %d %d %d\n",stu[i].id,stu[i].sum,stu[i].gs,stu[i].cx,stu[i].xd);
	}

}