[백준] P1157

동민·2021년 3월 11일
import java.util.Scanner;

public class P1157 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.nextLine();

		char[] arr = new char[s.length()];

		for (int i = 0; i < s.length(); i++) {

			arr[i] = s.charAt(i);

		}

		int count, max;
		char result = ' ';

		int f = 'a' - 'A';
		int temp = 0;
		max = 0;
		for (char i = 'a'; i <= 'z'; i++) {
			count = 0;

			for (int j = 0; j < arr.length; j++) {

				if (arr[j] == i || arr[j] == (char) (i - f)) {
					count++;
				}

			}
			if (max < count) {
				max = count;
				result = i;
				temp = 1;
			} else if (max == count) {
				result = '?';
				temp = 0;
			}
		}

		if (temp == 0) {
			System.out.println(result);
		} else {
			System.out.println((char) (result - f));

		}

		sc.close();

	}

}
profile
BE Developer

0개의 댓글