Notice
Recent Posts
Recent Comments
Link
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-1157번/Java] 단어공부 본문

Algorithm

[백준-1157번/Java] 단어공부

1984 2022. 11. 10. 20:17
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] alphabets = new int[('Z' - 'A' + 1)];

		for (int i = 0; i < alphabets.length; i++) {
			alphabets[i] = 0;
		}

		String str = sc.nextLine();
		for (char c : str.toUpperCase().toCharArray()) {
			alphabets[c - 'A'] += 1;
		}

		int max_num = -1;
		int max_cnt = 0;
		int max_index = -1;
		for (int i = 0; i < alphabets.length; i++) {
			if (alphabets[i] > max_num) {
				max_num = alphabets[i];
				max_index = i;
				max_cnt = 1;
			} else if (alphabets[i] == max_num) {
				max_cnt++;
			}
		}

		if (max_cnt > 1) {
			System.out.println("?");
		} else {
			System.out.println((char) ('A' + max_index));
		}

	}

}
728x90

'Algorithm' 카테고리의 다른 글

[백준-2908번/Java] 상수  (0) 2022.11.10
[백준-1152번/Java] 단어의 개수  (0) 2022.11.10
[백준-4344번/Java] 평균은 넘겠지  (0) 2022.11.10
[백준-8959번/Java] OX 퀴즈  (0) 2022.11.10
[백준-3052번/Java] 나머지  (0) 2022.11.10
Comments