import java.util.*;
class City implements Comparable < City >
{
private String name;
private int men, women;
public City (String name, int men, int women)
{
this.name = name;
this.men = men;
this.women=women;
}
@Override
public String toString ()
{
return String.format ("%s %d %d", this.name, this.men, this.women);
}
@Override
public int compareTo (City other)
{
if (this.men + this.women == other.men + other.women)
{
if (this.men == other.men)
{
return this.name.compareTo (other.name);
}
return other.men - this.men;
}
return (other.men + other.women) - (this.men + this.women);
}
}
public class Hello
{
public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
int N = Integer.parseInt (sc.nextLine ().trim ());
List < City > cities = new ArrayList <> ();
for (int ctr = 1; ctr <= N; ctr++)
{
String currCity[] = sc.nextLine ().trim ().split ("\\s+");
cities.
add (new
City (currCity[0], Integer.parseInt (currCity[1]),
Integer.parseInt (currCity[2])));
} Collections.sort (cities);
for (City city:cities)
{
System.out.println (city);
}
}
}
0 Comments