Result: Accepted
Time: 1077ms
Memory: 1368kB
#include<stdio.h>
#include<string.h>
struct Struct{
char id[10];
int zcj;
int gdsx;
int cxsj;
int xxds;
}a[10010],temp;
int main(){
int N,Q;
int qu,qukc;
char quid[10];
double sumgdsx=0,sumcxsj=0,sumxxds=0;
scanf("%d",&N);
for(int i=1;i<=N;i++){
scanf("%s %d %d %d",a[i].id,&a[i].gdsx,&a[i].cxsj,&a[i].xxds);
a[i].zcj=a[i].cxsj+a[i].gdsx+a[i].xxds;
sumgdsx+=a[i].gdsx;
sumcxsj+=a[i].cxsj;
sumxxds+=a[i].xxds;
}
scanf("%d",&Q);
for(int i=1;i<=Q;i++){
scanf("%d",&qu);
if(qu==1){
scanf("%s",quid);
for(int j=1;j<=N;j++){
if(strcmp(a[j].id,quid)==0){
printf("Query #%d: 1 %s\n",i,quid);
printf("%d %d %d %d\n",a[j].zcj,a[j].gdsx,a[j].cxsj,a[j].xxds);
}
}
}
else if(qu==2){
scanf("%d",&qukc);
printf("Query #%d: 2 %d\n",i,qukc);
if(qukc==1)
printf("%.2lf\n",sumgdsx/N);
else if(qukc==2)
printf("%.2lf\n",sumcxsj/N);
else
printf("%.2lf\n",sumxxds/N);
}
}
for(int i=1;i<N;i++){
for(int j=1;j<=N-i;j++){
if(a[j].zcj<a[j+1].zcj){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
else if(a[j].zcj==a[j+1].zcj&&a[j].gdsx<a[j+1].gdsx){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
else if(a[j].zcj==a[j+1].zcj&&a[j].gdsx==a[j+1].gdsx&&a[j].cxsj<a[j+1].cxsj){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
else if(a[j].zcj==a[j+1].zcj&&a[j].gdsx==a[j+1].gdsx&&a[j].cxsj==a[j+1].cxsj&&a[j].xxds<a[j+1].xxds){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
else if(a[j].zcj==a[j+1].zcj&&a[j].gdsx==a[j+1].gdsx&&a[j].cxsj==a[j+1].cxsj&&a[j].xxds==a[j+1].xxds&&strcmp(a[j].id,a[j+1].id)>0){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int i=1;i<=N;i++){
printf("%s %d %d %d %d\n",a[i].id,a[i].zcj,a[i].gdsx,a[i].cxsj,a[i].xxds);
}
}