Repository navigation
Expand file tree
/
Copy pathGuess2966.java
More file actions
83 lines (63 loc) · 1.77 KB
/
Copy pathGuess2966.java
File metadata and controls
83 lines (63 loc) · 1.77 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
package boj;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Guess2966 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
String[] sArr = br.readLine().split("");
String[] arr1 = {"A", "B", "C"};
String[] arr2 = {"B", "A", "B", "C"};
String[] arr3 = {"C", "C", "A", "A", "B", "B"};
List<Applicant> list = new ArrayList<>();
list.add(new Applicant("Adrian", 0, arr1));
list.add(new Applicant("Bruno", 0, arr2));
list.add(new Applicant("Goran", 0, arr3));
for (Applicant a : list) {
a.test(sArr);
}
Collections.sort(list);
int max = list.get(0).getScore();
System.out.println(max);
for (Applicant a : list) {
if(max == a.getScore()) System.out.println(a.getName());
}
}
}
class Applicant implements Comparable<Applicant>{
private String name;
private int score;
private String[] arr;
public Applicant(String name, int score, String[] arr) {
this.name = name;
this.score = score;
this.arr = arr;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
public void test(String[] problems) {
for(int i = 0; i < problems.length; i++) {
if(problems[i].equals(this.arr[i % arr.length])) score++;
}
}
@Override
public String toString() {
return "Applicant [name=" + name + ", score=" + score + "]";
}
@Override
public int compareTo(Applicant a) {
// TODO Auto-generated method stub
if(this.score < a.score) return 1;
if(this.score > a.score) return -1;
return this.name.compareTo(a.name);
}
}