-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassyProblem.java
72 lines (67 loc) · 2.44 KB
/
ClassyProblem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
public class ClassyProblem {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int cases = Integer.parseInt(bf.readLine());
for(int i = 0; i < cases; i++) {
int people = Integer.parseInt(bf.readLine());
ArrayList<Person> lst = new ArrayList<>();
for(int j = 0; j < people; j++) {
String[] input = bf.readLine().split(" ");
String name = input[0].replace(":","");
lst.add(new Person(name, input[1]));
}
Collections.sort(lst);
for(int k = 0; k < lst.size(); k++) {
writer.println(lst.get(k).name);
}
writer.write("=====================================================");
writer.println();
}
bf.close();
writer.flush();
writer.close();
}
public static class Person implements Comparable<Person> {
String name;
ArrayList<Integer> ranks;
public Person(String name, String position) {
this.name = name;
this.ranks = new ArrayList<>();
String[] ranking = position.split("-");
for(int i = ranking.length - 1; i >= 0; i--) {
if (ranking[i].equals("upper")) {
ranks.add(3);
} else if (ranking[i].equals("middle")) {
ranks.add(2);
} else {
ranks.add(1);
}
}
for (int i = 0; i < 10; i++) {
ranks.add(2);
}
}
@Override
public int compareTo(Person o) {
for (int i = 0; i < 10; i++) {
if (this.ranks.get(i).equals(o.ranks.get(i))) {
continue;
}
if (this.ranks.get(i) > o.ranks.get(i)) {
return -1;
}
if (this.ranks.get(i) < o.ranks.get(i)) {
return 1;
}
}
return this.name.compareTo(o.name);
}
}
}