#include <stdio.h> #include <string.h> #include <stdlib.h> struct ph { char name[100]; double p; double q; double sum; }; int cmp(const void*a,const void*b) { if((*(struct ph*)b).sum-(*(struct ph*)a).sum>0) { return 1; } else { return -1; } } int main() { int n; scanf("%d",&n); for(int i=0;i<n;i++) { struct ph phone[1100]; int m; scanf("%d",&m); for(int j=0;j<m;j++) { scanf("%s %lf %lf",phone[j].name,&phone[j].p,&phone[j].q); phone[j].sum=phone[j].p/phone[j].q; } qsort(phone,m,sizeof(phone[0]),cmp); for(int j=0;j<m;j++) { printf("%d %s %.0lf %.0lf\n",j+1,phone[j].name,phone[j].p,phone[j].q); } } return 0; } |
Double click to view unformatted code.