#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> typedef struct Phone{ char name[30]; double p; double q; double x; }phone; int main(){ int t,n; scanf("%d",&t); while(t--){ scanf("%d",&n); phone ph[n]; for(int i=0;i<n;i++){ scanf("%s %lf %lf",ph[i].name,&ph[i].p,&ph[i].q); ph[i].x=ph[i].p/ph[i].q; } for(int i=n-1;i>0;i--){ int flag=0; for(int j=0;j<i;j++){ if(ph[j].x<ph[j+1].x){ phone tmp; tmp=ph[j]; ph[j]=ph[j+1]; ph[j+1]=tmp; flag=1; } } if(flag==0){ break; } } for(int i=0;i<n;i++){ printf("%d %s %.0lf %.0lf\n",i+1,ph[i].name,ph[i].p,ph[i].q); } } return 0; } |
Double click to view unformatted code.