#include <iostream>
using namespace std;
int main() {
int alphabet[26] = { 0 };
int max = 0, maxIndex = 0;
int maxCount = 0; // 가장 많이 사용된 알파벳이 여러개 존재하는 경우를 위한 변수
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') { // s[i]가 대문자라면
alphabet[s[i] - 'A']++;
}
else {
alphabet[s[i] - 'a']++;
}
}
max = alphabet[0];
maxIndex = 0;
// 가장 많이 사용된 알파벳의 count값과 index를 추출
for (int i = 1; i < 26; i++) {
if (max < alphabet[i]) {
max = alphabet[i];
maxIndex = i;
}
}
// 가장 많이 사용된 알파벳이 여러개면 "?" 출력
for (int i = 0; i < 26; i++) {
if (max == alphabet[i]) maxCount++;
if (maxCount > 1) {
cout << "?";
return 0;
}
}
// 가장 많이 사용된 알파벳이 하나면 maxIndex에 'A' 값을 더해 대문자로 출력
char result = maxIndex + 'A';
cout << result;
return 0;
}
728x90
'Baekjoon' 카테고리의 다른 글
백준 #4963 [c++] (0) | 2021.08.30 |
---|---|
백준 #14502 [c++] (0) | 2021.08.28 |
백준 #1697 [c++] (0) | 2021.08.02 |
백준 #2577 [c++] (0) | 2021.08.02 |
백준 #1012 [c++] (0) | 2021.08.01 |