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: 29ms
Memory: 1448kB
In contest: 1258

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

typedef struct student
{
	char num[6];
	int s1,s2,s3;
	int  total;
}stu;

int cmp(const void *p,const void *q)
{
	stu *a=(stu *)p;
	stu *b=(stu *)q;
	if (a->total != b->total)
		return b->total - a->total;
	else if (a->s1 != b->s1)
		return b->s1 - a->s1;
	else if (a->s2 != b->s2)
		return b->s2 - a->s2;
	else if (a->s3 != b->s3)
		return b->s3 - a->s3;
	else 
		return strcmp(a->num,b->num);
}



int main()
{
	char x[10];
	double ave[3]={0};
	int n,q,p;
	scanf("%d",&n);
	stu s[n];
	for (int i=0;i<n;i++)
	{
		scanf ("%s%d%d%d",&s[i].num,&s[i].s1,&s[i].s2,&s[i].s3);
		s[i].total=s[i].s1+s[i].s2+s[i].s3;
		ave[0]+=s[i].s1;
		ave[1]+=s[i].s2;
		ave[2]+=s[i].s3;
	}
	for (int i=0;i<3;i++)
		ave[i]/=n;
	scanf("%d",&q);
	for (int i=1;i<=q;i++)
	{
		int tmp;
		scanf("%d",&tmp);
		if (tmp==1)
		{
			scanf("%s",x);
			printf("Query #%d: 1 %s\n",i,x);
			for (int k=0;k<n;k++)
				if (strcmp(s[k].num,x)==0)
				printf("%d %d %d %d\n",s[k].total,s[k].s1,s[k].s2,s[k].s3);
		}
		else
		{
			scanf("%d",&p);
			printf("Query #%d: 2 %d\n",i,p);
			printf("%.2f\n",ave[p-1]);
		}
	}
	qsort(s,n,sizeof(s[0]),cmp);
	for (int i=0;i<n;i++)
	{
		printf("%s %d %d %d %d\n",s[i].num,s[i].total,s[i].s1,s[i].s2,s[i].s3);
	}
}