Result: Accepted
Time: 33ms
Memory: 1392kB
#include <stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
struct student
{
int gaoshu, ciyuyan,xiandai,zongfen,xuehao;
};
int cmp(const void*q,const void *p)
{
struct student *a=(struct student*)q;
struct student *b=(struct student*)p;
if(a->zongfen > b->zongfen)
{
return -1;
}
else if(a->zongfen < b->zongfen)
{
return 1;
}
else
{
if(a->gaoshu>b->gaoshu)
{
return -1;
}
else if(a->gaoshu<b->gaoshu)
{
return 1;
}
else
{
if(a->ciyuyan>b->ciyuyan)
{
return -1;
}
else if(a->ciyuyan<b->ciyuyan)
{
return 1;
}
else
{
if(a->xiandai>b->xiandai)
{
return -1;
}
else if(a->xiandai<b->xiandai)
{
return 1;
}
else
{
if(a->xuehao>b->xuehao)
{
return 1;
}
else
{
return -1;
}
}
}
}
}
}
int main()
{
struct student chenji[11000];
int n,i,a,m,count=1,s;
double m1=0,m2=0,m3=0;
scanf("%d",&n);
for(i=0;i<n;++i)
{
scanf("%d %d %d %d",&chenji[i].xuehao,&chenji[i].gaoshu,&chenji[i].ciyuyan,&chenji[i].xiandai);
chenji[i].zongfen=chenji[i].gaoshu+chenji[i].xiandai+chenji[i].ciyuyan;
m1+=chenji[i].gaoshu;
m2+=chenji[i].ciyuyan;
m3+=chenji[i].xiandai;
}
scanf("%d",&a);
while(a--)
{
scanf("%d %d",&m,&s);
if(m==1)
{
for(i=0;i<n;++i)
{
if(chenji[i].xuehao==s)
{
printf("Query #%d: %d %05d\n",count,m,chenji[i].xuehao);
printf("%d %d %d %d\n",chenji[i].zongfen,chenji[i].gaoshu,chenji[i].ciyuyan,chenji[i].xiandai);
}
}
}
if(m==2)
{
if(s==1)
{
printf("Query #%d: %d %d\n",count,m,s);
printf("%.2f\n",m1/n);
}
else if(s==2)
{
printf("Query #%d: %d %d\n",count,m,s);
printf("%.2f\n",m2/n);
}
else if(s==3)
{
printf("Query #%d: %d %d\n",count,m,s);
printf("%.2f\n",m3/n);
}
}
++count;
}
qsort(chenji,n,sizeof(struct student),cmp);
for(i=0;i<n;++i)
{
printf("%05d %d %d %d %d\n",chenji[i].xuehao,chenji[i].zongfen,chenji[i].gaoshu,chenji[i].ciyuyan,chenji[i].xiandai);
}
}