-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclassypeople.java
More file actions
73 lines (61 loc) · 1.6 KB
/
classypeople.java
File metadata and controls
73 lines (61 loc) · 1.6 KB
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
/*
Solution to https://rmc15.kattis.com/problems/classy
Rocky Mountain Regional Contest 2015
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class classypeople {
public static class person implements Comparable<person>{
public String name;
public ArrayList<Integer> rank;
public person(){}
public person(String name, String title){
this.name = name;
this.rank = new ArrayList<Integer>();
String[] edit = title.split("-");
for(int i = edit.length-1; i >= 0; i--){
if(edit[i].equals("upper")) rank.add(3);
else if(edit[i].equals("middle")) rank.add(2);
else rank.add(1);
}
String end = edit[edit.length-1];
int val = 0;
for(int i = 0; i < 10; i++){
rank.add(2);
}
}
@Override
public int compareTo(person o) {
person p = (person)o;
for(int i = 0; i < 10; i++){
if(this.rank.get(i) == p.rank.get(i))
continue;
if(this.rank.get(i) > p.rank.get(i))
return -1;
if(this.rank.get(i)< p.rank.get(i))
return 1;
}
return this.name.compareTo(p.name);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int z=0; z<t; z++){
int n = in.nextInt();
in.nextLine();
ArrayList<person> list= new ArrayList<person>() ;
for(int i = 0; i< n; i++){
String[] s = in.nextLine().split(" ");
String word = s[0].replaceAll(":","");
list.add(new person(word, s[1]));
}
Collections.sort(list);
for(person p:list){
System.out.println(p.name);
}
System.out.println("==============================");
}
}
}