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: 32ms
Memory: 1368kB
In contest: 1258

#include<stdio.h>
#include<stdlib.h>
typedef struct my
{
	int num;
	int math;
	int it;
	int xian;
	int sum;
}my;
int comp (const void * a,const void *b)
{
	if((((struct my *)a)->sum)<(((struct my *)b)->sum))
		return 1;
	else if((((struct my *)a)->sum)>(((struct my *)b)->sum))
		return 0;
	else
	{
		if((((struct my *)a)->math)<(((struct my *)b)->math))
			return 1;
		else if((((struct my *)a)->math)>(((struct my *)b)->math))
			return 0;
		else
		{
			if((((struct my *)a)->it)<(((struct my *)b)->it))
			return 1;
		else if((((struct my *)a)->it)>(((struct my *)b)->it))
			return 0;
			else
			{
				if((((struct my *)a)->xian)<(((struct my *)b)->xian))
					return 1;
				else if((((struct my *)a)->xian)>(((struct my *)b)->xian))
					return 0;
				else
				{
					if((((struct my *)a)->num)>(((struct my *)b)->num))
						return 1;
					else if((((struct my *)a)->num)<(((struct my *)b)->num))
						return 0;
				}
			}
		}
	}
}
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
int main(void)
{
	my sz[10010]; 
	int n, i, j, q, a, b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d%d",&sz[i].num,&sz[i].math,&sz[i].it,&sz[i].xian);
		sz[i].sum=sz[i].math+sz[i].it+sz[i].xian;
	}
	scanf("%d",&q);
	for(j=1;j<=q;j++)
	{
		int su=0;
		scanf("%d %d",&a, &b);
		if(a==1) 
		{
			printf("Query #%d: 1 %0.5d\n",j,b);
			for(i=0;i<n;i++)
				{
					if(sz[i].num==b)
						printf("%d %d %d %d\n",sz[i].sum,sz[i].math,sz[i].it,sz[i].xian);
			}
		}
		else
		{ 
			printf("Query #%d: 2 %d\n",j,b);
			for(i=0;i<n;i++)
			{
				if(b==1) su+=sz[i].math;
				else if(b==2) su+=sz[i].it;
				else if(b==3) su+=sz[i].xian;
			}
			printf("%.2f\n",su*1.0/n);
		}
	}
	qsort(sz,n,sizeof(my),comp);
	for(i=0;i<n;i++)
	{
		printf("%0.5d %d %d %d %d\n",sz[i].num,sz[i].sum,sz[i].math,sz[i].it,sz[i].xian);
	}
	return 0;
}