Result: Accepted
Time: 280ms
Memory: 1484kB
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
struct{
char hao[6];
double gaoshu;
double chengxv;
double xiandai;
double sum;
}a[10000];
int main(){
int n,q,Q,y,hao,i,k,p;
char x[6],u[6];
double gaoshusum=0,chengxvsum=0,xiandaisum=0,gaoshueva,chengxveva,xiandaieva,temp,max;
scanf("%d",&n);
for(i=0;i<n;++i){
scanf("%s",a[i].hao);
scanf("%lf%lf%lf",&a[i].gaoshu ,&a[i].chengxv ,&a[i].xiandai );
a[i].sum =a[i].gaoshu+a[i].chengxv+a[i].xiandai;
gaoshusum=a[i].gaoshu+gaoshusum;
chengxvsum=chengxvsum+a[i].chengxv ;
xiandaisum=xiandaisum+a[i].xiandai ;
}
gaoshueva=gaoshusum/n;
chengxveva=chengxvsum/n;
xiandaieva=xiandaisum/n;
scanf("%d",&q);
for(k=1;k<=q;++k){
scanf("%d",&Q);
if(Q==1){
scanf("%s",x);
printf("Query #%d: 1 %s\n",k,x);
for(i=0;i<n;++i){
if(strcmp(a[i].hao ,x)==0){
printf("%.0f %.0f %.0f %.0f\n",a[i].sum,a[i].gaoshu ,a[i].chengxv ,a[i].xiandai );
}
}
}
if(Q==2){
scanf("%d",&y);
if(y==1){
printf("Query #%d: 2 1\n",k);
printf("%.2f\n",gaoshueva);
}
if(y==2){
printf("Query #%d: 2 2\n",k);
printf("%.2f\n",chengxveva);
}if(y==3){
printf("Query #%d: 2 3\n",k);
printf("%.2f\n",xiandaieva);
}
}
}
for(k=0;k<n;++k){
max=a[k].sum ;
p=k;
for(i=k+1;i<n;++i){
if(a[i].sum >max ){
max=a[i].sum ;
p=i;
}
if(a[i].sum ==max){
if(a[i].gaoshu >a[p].gaoshu ){
max=a[i].sum ;
p=i;
}
if(a[i].gaoshu ==a[p].gaoshu ){
if(a[i].chengxv >a[p].chengxv ){
max=a[i].sum ;
p=i;
}
if(a[i].chengxv ==a[p].chengxv ){
if(a[i].xiandai >a[p].xiandai ){
max=a[i].sum;
p=i;}
if(a[i].xiandai==a[p].xiandai ){
if(strcmp(a[i].hao ,a[p].hao )<0){
max=a[i].sum ;
p=i;
}
}
}
}
}
}
temp=a[k].sum ;
a[k].sum =a[p].sum ;
a[p].sum =temp;
temp=a[k].gaoshu ;
a[k].gaoshu =a[p].gaoshu ;
a[p].gaoshu =temp;
temp=a[k].chengxv ;
a[k].chengxv =a[p].chengxv ;
a[p].chengxv =temp;
temp=a[k].xiandai ;
a[k].xiandai =a[p].xiandai ;
a[p].xiandai =temp;
strcpy(u,a[k].hao ) ;
strcpy(a[k].hao,a[p].hao ) ;
strcpy(a[p].hao,u ) ;
}
for(i=0;i<n;++i){
printf("%s %.0f %.0f %.0f %.0f\n",a[i].hao ,a[i].sum ,a[i].gaoshu ,a[i].chengxv ,a[i].xiandai );
}
return 0;
}