Skip to content

Instantly share code, notes, and snippets.

@johirbuet
Created March 15, 2018 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johirbuet/1b8fe150289559e51953a90481a41f69 to your computer and use it in GitHub Desktop.
Save johirbuet/1b8fe150289559e51953a90481a41f69 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class UVA11804 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = Integer.parseInt(sc.nextLine());
for(int t = 1; t<= T; t++) {
PriorityQueue<Player> pq = new PriorityQueue<>();
for(int i =0; i<10;i++) {
String [] line = sc.nextLine().split(" ");
String name = line[0];
int A = Integer.parseInt(line[1]);
int D = Integer.parseInt(line[2]);
Player p = new Player(A, D, name);
pq.add(p);
}
List<String> attackers = new ArrayList<>();
List<String> defenders = new ArrayList<>();
for(int i =0; i< 5; i++) {
attackers.add(pq.poll().name);
}
for(int i =0; i< 5; i++) {
defenders.add(pq.poll().name);
}
System.out.printf("Case %d:\n",t);
System.out.print("(");
Collections.sort(attackers);
Collections.sort(defenders);
for(int i =0 ; i< 4 ;i++) {
System.out.print(attackers.get(i)+", ");
}
System.out.println(attackers.get(4)+")");
System.out.print("(");
for(int i =0 ; i< 4 ;i++) {
System.out.print(defenders.get(i)+", ");
}
System.out.println(defenders.get(4)+")");
}
sc.close();
}
static class Player implements Comparable<Player> {
int A;
int D;
String name;
public Player(int A, int D, String name) {
this.A = A;
this.D = D;
this.name = name;
}
@Override
public int compareTo(Player o) {
if(this.A == o.A) {
return this.D - o.D;
}
return o.A - this.A;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment