-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJ1156.java
More file actions
85 lines (65 loc) · 1.56 KB
/
BJ1156.java
File metadata and controls
85 lines (65 loc) · 1.56 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
package javaBackjoon;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
class Alphabet {
private char alphabet;
private int count;
// 알파벳의 처음 횟수 설정은 0이어야
Alphabet() {count = 0;};
public void setAlphabet(char tmpChat) {
alphabet = tmpChat;
}
public void addCnt() {
count += 1;
}
public int getCnt() {
return count;
}
public char getAlphabet() {
return alphabet;
}
}
class reverseCmp implements Comparator<Alphabet> {
public int compare(Alphabet first, Alphabet second) {
int firstCnt = first.getCnt();
int secondCnt = second.getCnt();
if(firstCnt > secondCnt) {
return -1;
}
else if (firstCnt < secondCnt) {
return 1;
}
else {
return 0;
}
}
}
public class BJ1156 extends ArrayList<Alphabet> {
static void setAryList(ArrayList<Alphabet> aryAlphabet) {
for(int i = 0; i < 26; i++) {
Alphabet tmp = new Alphabet();
tmp.setAlphabet((char) ('A' + i));
aryAlphabet.add(i, tmp);
}
}
public static void main(String[] args) {
ArrayList<Alphabet> ary = new ArrayList<Alphabet>(26);
setAryList(ary);
Scanner input = new Scanner(System.in);
String getData = input.nextLine();
getData = getData.toLowerCase();
for(char tmp : getData.toCharArray()) {
ary.get(tmp-'a').addCnt();
}
reverseCmp tmpCmp = new reverseCmp();
Collections.sort(ary, tmpCmp);
if(ary.get(0).getCnt() == ary.get(1).getCnt()) {
System.out.println('?');
}
else {
System.out.println(ary.get(0).getAlphabet());
}
}
}