import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); int t=Integer.parseInt(scanner.nextLine()); while(t-->0) { int n=Integer.parseInt(scanner.nextLine()); Phone[] phones=new Phone[n]; for(int i=0;i<n;i++) { String[] temp=scanner.nextLine().split(" "); Main.Phone tp=new Main().new Phone(); tp.name=temp[0]; tp.p=temp[1]; tp.q=temp[2]; tp.pq=Integer.parseInt(temp[1])*1.0/Integer.parseInt(temp[2]); phones[i]=tp; } for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { Main.Phone temp=new Main().new Phone(); if(phones[i].pq<phones[j].pq) { temp=phones[i]; phones[i]=phones[j]; phones[j]=temp; } } } for(int i=1;i<=n;i++) { System.out.println(i+" "+phones[i-1].name+" "+phones[i-1].p+" "+phones[i-1].q); } } } class Phone implements Comparable{ String name; String p; String q; double pq; @Override public int compareTo(Object o) { // TODO Auto-generated method stub Phone p=(Phone)o; return (int) (0-(this.pq-p.pq)); } } } |
Double click to view unformatted code.