본문 바로가기
휴지통/알고리즘 & 자료구조

백준 1157_1

by 신재권 2022. 3. 11.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main1157 {

	public static void main(String[] args) throws IOException {
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	     
		 String s = br.readLine().toUpperCase();
		 int[] cnt = new int[26];
		 
		 int max = 0;
		 char maxAlpha = '?';
		 
		 for(int i=0; i<s.length(); i++) {
			 cnt[s.charAt(i)-'A']++;
			 if(max < cnt[s.charAt(i)-'A']) {
				 max = cnt[s.charAt(i)-'A'];
				 maxAlpha = s.charAt(i);
			 }else if(max == cnt[s.charAt(i)-'A']) maxAlpha='?';
		 }

		 System.out.println(maxAlpha);
	}

	
}

'휴지통 > 알고리즘 & 자료구조' 카테고리의 다른 글

백준 14889  (0) 2022.03.13
문자열 압축 [Java]  (0) 2022.03.12
백준 18108  (0) 2022.03.10
신규 아이디 추천[Java]  (0) 2022.03.09
신고 결과 받기 [Java]  (0) 2022.03.08