#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string testStr;
    cin >> testStr;
    int alphabetCnt[26] = {0};
    int max = 0,
        maxIdx = 0;
    
    for(int i = 0 ; i < testStr.size(); i++) {
        if(testStr[i] > 90) {
            testStr[i] = toupper(testStr[i]);
        }

        alphabetCnt[testStr[i] - 65]++;
        if(max < alphabetCnt[testStr[i] - 65]) {
            max = alphabetCnt[testStr[i] - 65];
            maxIdx = testStr[i] - 65;
        }
    }

    for(int i = 0 ; i < 26; i++) {
        if(alphabetCnt[i] == alphabetCnt[maxIdx] && maxIdx != i) {
            cout << '?' << '\n';
            return 0;
        }
    }

    cout << (char)(maxIdx + 65) << '\n';
    return 0;
}

알파벳 관련된 문제는 아스키 코드를 사용하자. 다시금 기초의 중요함을 느낀다.

풀이는 하단의 사이트를 참고했습니다. 감사합니다.

https://mtoc.tistory.com/26

'문제풀이 > 백준' 카테고리의 다른 글

5622 - 다이얼  (0) 2021.08.24
1152 - 단어의 개수  (0) 2021.08.24
11720 - 숫자의 합  (0) 2021.08.24
11654 - 아스키 코드  (0) 2021.06.22
10171 - 고양이  (0) 2021.06.22

+ Recent posts