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: 30ms
Memory: 1444kB
In contest: 1258

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

typedef struct Stu {
	char name[9];
	int gd;
	int xc;
	int xx;
}stu;
int cmp(const void *a, const void *b) {
	stu c = *(stu*)a;
	stu d = *(stu*)b;
	double sumc,sumd;
	sumc=c.gd+c.xc+c.xx;
	sumd=d.gd+d.xc+d.xx;
	if(sumc!=sumd)
		return-(sumc-sumd);
	else if(c.gd!=d.gd)
		return-(c.gd-d.gd);
	else if(c.xc!=d.xc)
		return-(c.xc-d.xc);
	else if(c.xx!=d.xx)
		return-(c.xx-d.xx);
	else
		return(strcmp(c.name,d.name));

}
int main()
{
	int t, hs,i,j,n,q,type;
	double gdsum=0,xcsum=0,xxsum=0;
	char sid[9];
	stu cj[10020];
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%s %d %d %d", &cj[i].name,&cj[i].gd,&cj[i].xc,&cj[i].xx);
		gdsum+=cj[i].gd;
		xcsum+=cj[i].xc;
		xxsum+=cj[i].xx;

	}
	qsort(cj,n,sizeof(cj[0]),cmp);

	scanf("%d",&q);
	for(j=1;j<=q;j++)
	{
		scanf("%d %s",&type,&sid);
		if(type==1)
		{
			for(i=0;i<=n;i++)
			{
				if (strcmp(sid,cj[i].name)==0)
				{
					printf("Query #%d: %d %s\n%d %d %d %d\n",j,type,sid,(cj[i].gd+cj[i].xc+cj[i].xx),cj[i].gd,cj[i].xc,cj[i].xx);
					break;
				}
			}
		}
		else
		{
			if(strcmp(sid,"1")==0)
				printf("Query #%d: 2 1\n%.2f\n",j,(gdsum/n));
			if(strcmp(sid,"2")==0)
				printf("Query #%d: 2 2\n%.2f\n",j,(xcsum/n));
			if(strcmp(sid,"3")==0)
				printf("Query #%d: 2 3\n%.2f\n",j,(xxsum/n));
		}
		
	}
	for(i=0;i<n;i++)
	{
		printf("%s %d %d %d %d\n",cj[i].name,(cj[i].gd+cj[i].xc+cj[i].xx),cj[i].gd,cj[i].xc,cj[i].xx);
	}
	return 0;
}