-
Notifications
You must be signed in to change notification settings - Fork 19
/
classy.java
81 lines (54 loc) · 1.37 KB
/
classy.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
73
74
75
76
77
78
79
80
81
import java.util.Arrays;
public class classy {
public static void main(String[] args) {
Kattio scan = new Kattio(System.in);
int cases = scan.getInt();
while (cases --> 0)
{
int names = scan.getInt();
Person[] people = new Person[names];
for (int i = 0; i < people.length; i++)
{
people[i] = new Person(scan.getWord() , scan.getWord());
scan.getWord();
}
Arrays.sort(people);
for (Person x : people)
System.out.println(x);
System.out.println("==============================");
}
scan.close();
}
}
class Person implements Comparable<Person> {
String name;
int rank;
public Person (String name , String rank) {
this.name = name.substring(0 , name.length() - 1);
this.rank = rank(rank);
}
private char word(String rank) {
if (rank.equals("upper"))
return '2';
if (rank.equals("middle"))
return '1';
return '0';
}
private int rank(String str) {
String[] uml = str.split("-");
char[] base3 = new char[12];
Arrays.fill(base3 , '1');
for (int i = 12 - uml.length; i < base3.length; i++)
base3[i] = word(uml[i - (12 - uml.length)]);
String tritString = new String(new StringBuilder(new String(base3)).reverse());
return Integer.parseInt(tritString , 3);
}
public int compareTo(Person p) {
if (this.rank == p.rank)
return this.name.compareTo(p.name);
return p.rank - this.rank;
}
public String toString() {
return this.name;
}
}