Result: Accepted
Time: 26ms
Memory: 1372kB
#include<stdio.h>
#include<stdlib.h>
struct student{
int xh,gs,c,xd,total;
};
int cmp(const void *p,const void *q){
if(((struct student*)q)->total-((struct student*)p)->total!=0)
return ((struct student*)q)->total-((struct student*)p)->total;
else {
if(((struct student*)q)->gs-((struct student*)p)->gs!=0)
return ((struct student*)q)->gs-((struct student*)p)->gs;
else{
if(((struct student*)q)->c-((struct student*)p)->c!=0)
return ((struct student*)q)->c-((struct student*)p)->c;
else{
if(((struct student*)q)->xd-((struct student*)p)->xd!=0)
return ((struct student*)q)->xd-((struct student*)p)->xd;
else
return ((struct student*)p)->xh-((struct student*)q)->xh;
}
}
}
}
int main(){
int N,num1=0,num2=0,num3=0,s=0;
scanf("%d",&N);
struct student students[10100];
for(int i=0;i<N;i++){
scanf("%d%d%d%d",&students[i].xh,&students[i].gs,&students[i].c,&students[i].xd);
students[i].total=students[i].gs+students[i].c+students[i].xd;
num1+=students[i].gs;num2+=students[i].c;num3+=students[i].xd;
}
qsort(students,N,sizeof(struct student),cmp);
int Q;
scanf("%d",&Q);
for(int l=1;l<=Q;l++){
int a,b;
scanf("%d%d",&a,&b);
if(a==1)
{
for(int i=0;i<N;i++){
if(b==students[i].xh)
{
printf("Query #%d: %d ",l,a);
int o=students[i].xh;
s=0;
while(o>0){
o=o/10;
s++;
}
for(int j=0;j<5-s;j++) printf("0");
if(students[i].xh!=0) printf("%d\n",students[i].xh);
printf("%d %d %d %d\n",students[i].total,students[i].gs,students[i].c,students[i].xd);
}
}
}
if(a==2)
{
printf("Query #%d: %d %d\n",l,a,b);
if(b==1) printf("%.2f\n",num1*1.0/N);
if(b==3) printf("%.2f\n",num3*1.0/N);
if(b==2) printf("%.2f\n",num2*1.0/N);
}
}
for(int i=0;i<N;i++){
s=0;
int h=students[i].xh;
while(students[i].xh>0){
students[i].xh=students[i].xh/10;
s++;
}
for(int j=0;j<5-s;j++) printf("0");
if(h!=0) printf("%d",h);
printf(" %d %d %d %d\n",students[i].total,students[i].gs,students[i].c,students[i].xd);
}
}