알고리즘 풀이/백준

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

배게 2021. 6. 26. 14:58
728x90
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
32
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
 
 
public class Main {
        
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    
    public static void main(String[] args) throws IOException{
        // 어떻게 할 것인가.
        String input = br.readLine().toUpperCase();
        char[] charInput = input.toCharArray();
        int[] aToZ = new int[26];
        char result=' ';
        int max = 0;
        
        for(int i=0; i<charInput.length; i++) {
            aToZ[charInput[i]-'A']++;
        }
        
        for(int i=0; i<aToZ.length; i++) {
            if(max<aToZ[i]) {
                max=aToZ[i];
                result=(char)(i+'A');
            }
            else if(max==aToZ[i])  result='?';
        }
        
        
        
        bw.write(String.valueOf(result));
        bw.flush();
        
        
        
    }
}
cs