View Code of Problem 3861

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = 1;
		int t = Integer.parseInt(scan.nextLine());
		while (t-->0) {
			int n = Integer.parseInt(scan.nextLine());
			Phone[] phones = new Phone[n];
			for (int i = 0; i < phones.length; i++) {
				phones[i] = new Phone(scan.next(), Integer.parseInt(scan.next()), Integer.parseInt(scan.next()));
				
			}
			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.


Back to problem 3861