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: 1556kB
In contest: 1258

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
struct la
{
	char n[5];
	int a,b,c,s;
};
struct la ss[10001];
int cmp(const void *q, const void *p)
{
	struct la *m=(struct la *)q;
	struct la *y=(struct la *)p;
	if(m->s!=y->s)
		return(y->s - m->s);
	else if(m->s==y->s&&m->a!=y->a)
		return(y->a - m->a);
	else if(m->s==y->s&&m->a==y->a&&m->b!=y->b)
		return(y->b - m->b);
	else if(m->s==y->s&&m->a==y->a&&m->b==y->b&&m->c!=y->c)
		return(y->c - m->c);
	else
		return(strcmp(m->n ,y->n));
}
int main()
{
	int n,t,i,f,j,u,w;
	double r[3]={0};
	char m[5];
	scanf("%d",&t);
	for(i=0;i<t;i++)
		{
			scanf("%s",ss[i].n);
			scanf("%d %d %d",&ss[i].a,&ss[i].b,&ss[i].c);
			ss[i].s=ss[i].a+ss[i].b+ss[i].c;
			r[0]+=ss[i].a;
			r[1]+=ss[i].b;
			r[2]+=ss[i].c;
	}
	qsort(ss,t,sizeof(ss[0]),cmp);
	scanf("%d",&w);
	for(i=1;i<=w;i++)
	{
		scanf("%d ",&f);
		if(f==1)
		{
			strcpy(m,"\0");
			scanf("%s",m);
			for(j=0;j<t;j++)
			{
				if(strcmp(m,ss[j].n)==0)
				{
					printf("Query #%d: 1 %s\n",i,m);
					printf("%d %d %d %d\n",ss[j].s,ss[j].a,ss[j].b,ss[j].c);
					break;
				}
			}
		}
		else
		{
			scanf("%d",&u);
			printf("Query #%d: %d %d\n%.2f\n",i,f,u,r[u-1]/t);
		}
	}
	for(i=0;i<t;i++)
		printf("%s %d %d %d %d\n",ss[i].n,ss[i].s,ss[i].a,ss[i].b,ss[i].c);
}