Algorithm
[1157]문자열 - 단어 공부
jaamong
2022. 4. 17. 14:36
문제
코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
int cnt[] = new int[26];
for (byte inputs : input.getBytes()) {
if (inputs >= 97) {
cnt[inputs - 'a']++;
} else {
cnt[inputs - 'A']++;
}
}
char res = 0;
int max = -1;
for (int i = 0; i < 26; i++) {
if (max < cnt[i]) {
max = cnt[i];
res = (char) ('A' + i);
} else if (max == cnt[i]) {
res = '?';
}
}
System.out.println(res);
}
}