

이거 무진장 어려워했던 기억이 납니다. 앞에서는 각 자료형별 변환 (캐스팅), 그리고 String 매소드의 기본적인 부분에 대한 기초적인 공부였다면, 이 문제는 논리적 난이도가 떡상한다고 생각하거든요.
주의할점은 알파벳 카운팅에 있어 대소문자를 가리지 않는다는 것, 이것을 어떻게 계산할 것이냐, 라는 부분이고,
그것이 여러개 존재할경우를 어떻게 인식시킬것이냐, 라는 두 부분이 있네요.
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));
int[] count = new int[26];
String str = br.readLine();
int maxcount = 0;
int max = 0;
int multicount = 0;
for (int i=0; i<str.length(); i++) {
for (int j=0; j<26; j++) {
if (str.charAt(i) == (65+j)) {
count[j]++;
} else if (str.charAt(i) == (97+j)) {
count[j]++;
}
}
}
for (int k=0; k<26; k++) {
if (count[k]>maxcount) {
maxcount = count[k];
max = k;
}
}
for (int l=0; l<26; l++) {
if (count[l] == maxcount) {
multicount++;
}
}
if (multicount >= 2) {
System.out.println("?");
} else {
System.out.println((char)(65+max));
}
}
}'백준 문제풀이 > 문자열' 카테고리의 다른 글
| 2908. 상수 (자바, JAVA) (0) | 2022.09.13 |
|---|---|
| 1152. 단어의 개수 (자바, Java) (0) | 2022.09.13 |
| 2675. 문자열반복 (자바, JAVA) (0) | 2022.09.13 |
| 10809. 알파벳 찾기 (자바, JAVA) (0) | 2022.09.13 |
| 11720. 숫자의 합 (자바, JAVA) (0) | 2022.09.13 |