백준1157: 단어 공부
문제
https://www.acmicpc.net/problem/1157
문제 풀이
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
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
HashMap<Character, Integer> map = new HashMap<>();
ArrayList<Character> list = new ArrayList<>();
String word = sc.next().toUpperCase();
int max = 0;
for (int i = 0; i < word.length(); i++) {
char c = word.charAt(i);
map.put(c, map.getOrDefault(c, 0) + 1);
max = Math.max(max, map.get(c));
}
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
if (entry.getValue() == max) {
list.add(entry.getKey());
}
}
System.out.println(list.size()>1 ? "?" : list.get(0));
}
}
댓글남기기