728x90
문제
https://www.acmicpc.net/problem/1157
풀이 코드
public class boj_1157 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String upperCase = s.toUpperCase();
int[] count = new int[26]; //알파벳당 사용된 개수를 저장
for (int i = 0; i < upperCase.length(); i++) {
count[upperCase.charAt(i) - 65]++;
}
boolean duplication = false; //최대 값이 중복인지 판별
int max = Integer.MIN_VALUE; //최대 값
int answer = Integer.MIN_VALUE; //최대 값의 배열 인덱스
for (int i = 0; i < count.length; i++) {
if (count[i] > max) {
duplication = false;
max = count[i];
answer = i;
} else if (count[i] == max) {
duplication = true;
}
}
if (duplication) {
System.out.println("?");
} else {
System.out.println((char)(answer+65));
}
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[알고리즘/백준] 2438 별찍기 - 1 (자바, StringBuilder) (0) | 2021.09.18 |
---|---|
[알고리즘/백준] 1546 평균(자바) (0) | 2021.09.18 |
[백준] 1152 단어의 개수 - 자바, StringTokenizer (0) | 2021.09.17 |
[백준] 2914 저작권 - 자바 (0) | 2021.09.16 |
[백준] 2845 파티가 끝나고 난 뒤 - 자바 (0) | 2021.09.16 |
댓글