-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_14184.java
More file actions
92 lines (80 loc) · 2.92 KB
/
Copy pathBOJ_14184.java
File metadata and controls
92 lines (80 loc) · 2.92 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// BOJ - 14184
// Problem Sheet - https://www.acmicpc.net/problem/14184
import java.util.*;
import java.io.*;
import java.util.stream.Collectors;
public class Main {
static class Logo implements Comparable<Logo> {
private final int id;
private int first;
private int second;
private int third;
private int score;
public Logo(int id) {
this.id = id;
}
public int getId() { return this.id; }
public int getFirst() { return this.first; }
public int getSecond() { return this.second; }
public int getThird() { return this.third; }
public int getScore() { return this.score; }
public void addFirst() {
this.first++;
this.score += 3;
}
public void addSecond() {
this.second++;
this.score += 2;
}
public void addThird() {
this.third++;
this.score += 1;
}
@Override
public int compareTo(Logo l) {
if (this.score == l.getScore()) {
if (this.first == l.getFirst()) {
if (this.second == l.getSecond()) {
return this.id - l.getId();
}
return l.getSecond() - this.second;
}
return l.getFirst() - this.first;
}
return l.getScore() - this.score;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
while (true) {
Map<Integer, Logo> logoMap = new HashMap<>();
int n = Integer.parseInt(br.readLine());
if (n == 0) break;
for (int i=0 ; i<n ; i++) {
String[] row = br.readLine().split(" ");
int d = Integer.parseInt(row[0]);
for (int j=1 ; j<=d ; j++) {
int logo = Integer.parseInt(row[j]);
if (!logoMap.containsKey(logo)) logoMap.put(logo, new Logo(logo));
if (j == 1) logoMap.get(logo).addFirst();
if (j == 2) logoMap.get(logo).addSecond();
if (j == 3) logoMap.get(logo).addThird();
}
}
List<Logo> logos = logoMap.values().stream().sorted().collect(Collectors.toList());
Logo prev = logos.get(0);
for (Logo logo : logos) {
if (!isSameRank(prev, logo)) break;
sb.append(logo.getId()).append(" ");
prev = logo;
}
sb.append("\n");
}
System.out.println(sb);
br.close();
}
private static boolean isSameRank(Logo l1, Logo l2) {
return l1.getScore() == l2.getScore() && l1.getFirst() == l2.getFirst() && l1.getSecond() == l2.getSecond();
}
}