Result: Accepted
Time: 32ms
Memory: 2312kB
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
typedef struct ac{
int x,y,z;
int tot;
char num[101];
}ac;
int cmp(const void*a,const void *b){
ac *c=(ac *)a;
ac *d=(ac *)b;
if(c->tot!=d->tot) return d->tot - c->tot;
else if(c->x!=d->x) return d->x - c->x;
else if(c->y!=d->y) return d->y - c->y;
else if(c->z!=d->z) return d->z - c->z;
else return (strcmp(c->num,d->num)>0);
}
int main(){
int n;
scanf("%d",&n);
ac acm[10001]; double tot1,tot2,tot3;
for(int i=0;i<n;++i){
scanf("%s%d%d%d",&acm[i].num,&acm[i].x,&acm[i].y,&acm[i].z);
acm[i].tot=acm[i].x+acm[i].y+acm[i].z;
tot1+=acm[i].x;
tot2+=acm[i].y;
tot3+=acm[i].z;
}
int m;
scanf("%d",&m);
for(int j=1;j<=m;++j){
int p;char q[1001];
scanf("%d%s",&p,&q);
printf("Query #%d: %d %s\n",j,p,q);
if(p==1){
for(int i=0;i<n;++i){
if(strcmp(acm[i].num,q)==0)
{
printf("%d %d %d %d\n",acm[i].tot,acm[i].x,acm[i].y,acm[i].z);
break;
}
}
}
else if(p==2){
if(strcmp(q,"1")==0) printf("%.2lf\n",tot1/(n*1.0));
if(strcmp(q,"2")==0) printf("%.2lf\n",tot2/(n*1.0));
if(strcmp(q,"3")==0) printf("%.2lf\n",tot3/(n*1.0));
}
}
qsort(acm,n,sizeof(ac),cmp);
for(int i=0;i<n;++i){
printf("%s %d %d %d %d\n",acm[i].num,acm[i].tot,acm[i].x,acm[i].y,acm[i].z);
}
}