import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = Integer.parseInt(scan.nextLine()); while (t-->0) { int k = 1; int n = Integer.parseInt(scan.nextLine()); Phone[] phones = new Phone[n]; for (int i = 0; i < phones.length; i++) { String[] strings = scan.nextLine().split("\\s+"); phones[i] = new Phone(strings[0], Integer.parseInt(strings[1]), Integer.parseInt(strings[2])); } for (int i = 0; i < phones.length; i++) { for (int j = i+1; j < phones.length; j++) { if (phones[i].xjb < phones[j].xjb) { Phone phone = phones[i]; phones[i] = phones[j]; phones[j] = phone; } } } for (Phone phone : phones) { System.out.println((k++)+" "+phone.name+" "+phone.points+" "+phone.price); } } } } class Phone implements Comparable<Phone>{ String name ; int points; int price; double xjb; public Phone(String name, int points, int price) { super(); this.name = name; this.points = points; this.price = price; this.xjb = points/price; } @Override public int compareTo(Phone o) { return (int) (o.xjb-this.xjb); } } |
Double click to view unformatted code.