import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; /** * @author Clayton Walker */ public class Scoreboard { public static void main (String[] args) throws FileNotFoundException { Scanner in = new Scanner (new File ("scoreboard.in")); PrintWriter out = new PrintWriter (new File ("scoreboard.out")); int cases = in.nextInt (); in.nextLine (); for (int i = 0; i < cases; i++) { HashMap contestants = new HashMap (); while (in.hasNextLine ()) { String line = in.nextLine (); if (!line.isEmpty ()) { Scanner line_in = new Scanner (line); int team = line_in.nextInt (); int prob = line_in.nextInt (); int time = line_in.nextInt (); char ans = line_in.next ().charAt (0); if (ans == 'C' || ans == 'I') { Contestant contestant; if (contestants.containsKey (team)) { contestant = contestants.get (team); } else { contestant = new Contestant (team); contestants.put (team, contestant); } if (ans == 'C') { contestant.addCorrectAnswer (prob, time); } else if (ans == 'I') { contestant.addIncorrectAnswer (prob); } else { // System.out.println ("Not a valid code path"); System.exit (1); } } } else { write (contestants, out); contestants = new HashMap (); } } write (contestants, out); } in.close (); out.close (); } private static void write (HashMap contestants, PrintWriter out) { List list = new ArrayList (); list.addAll (contestants.values ()); Collections.sort (list); for (Contestant cont : list) { // System.out.println (cont.team + " solved " + cont.problems_solved + " in " + cont.total_time); out.println (cont.team + " " + cont.problems_solved + " " + cont.total_time); } if (!list.isEmpty ()) { out.println (); } } } class Contestant implements Comparable { HashMap problems; int problems_solved, total_time, team; public Contestant (int number) { problems = new HashMap (); team = number; } void addIncorrectAnswer (int problem) { Problem prob; if (problems.containsKey (problem)) { prob = problems.get (problem); } else { prob = new Problem (); problems.put (problem, prob); } prob.incorrect (); update_problems (); } void addCorrectAnswer (int problem, int time) { Problem prob; if (problems.containsKey (problem)) { prob = problems.get (problem); } else { prob = new Problem (); problems.put (problem, prob); } prob.correct (time); update_problems (); } private void update_problems () { problems_solved = total_time = 0; for (Map.Entry prob : problems.entrySet ()) { // Integer key1 = entry1.getKey (); Problem problem = prob.getValue (); if (problem.solved) { problems_solved++; total_time += (problem.tries * 20) + problem.time; } } } @Override public int compareTo (Contestant o) { if (o.problems_solved > problems_solved) { return 1; } else if (o.problems_solved < problems_solved) { return -1; } else { if (o.total_time > total_time) { return -1; } else if (o.total_time < total_time) { return 1; } else { if (o.team > team) { return -1; } else if (o.team < team) { return 1; } else { // System.out.println ("Invalid code path, teams can't have the same number"); return 0; } } } } } class Problem { boolean solved; int tries; int time; void incorrect () { if (!solved) { tries++; } } void correct (int time) { if (!solved) { solved = true; this.time = time; } } }