on
[백준] 1157 단어 공부(자바)
[백준] 1157 단어 공부(자바)
문제
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)); } } }
728x90
from http://developer-hm.tistory.com/142 by ccl(A) rewrite - 2021-09-18 16:26:54