https://www.acmicpc.net/problem/1157
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int alpha[26] = { 0 };
for (int i = 0; i < s.length(); i++) {
if (96 < s[i] && s[i] < 123) s[i] = toupper(s[i]);
alpha[s[i] - 65]++;
}
int max_index = 0;
int max = alpha[0];
for (int j = 1; j < 26; j++)
if (max < alpha[j]) {
max = alpha[j];
max_index = j;
}
char alphabet = max_index + 65;
int cnt = 0;
for (int k = 0; k < 26; k++)
if (max == alpha[k]) cnt++;
if (cnt > 1) cout << "?\n";
else cout << alphabet << '\n';
}
'Programming > Algorithm' 카테고리의 다른 글
[C++] 백준 5622번 : 다이얼 (0) | 2019.02.05 |
---|---|
[C++] 백준 1316 번 : 그룹 단어 체커 (0) | 2019.02.05 |
[C++]백준 2908번 : 상수 (0) | 2019.02.04 |
[C++] 백준 2675번 : 문자열 반복 (0) | 2019.02.04 |
[C++] 백준 10809번 : 알파벳 찾기 (0) | 2019.02.04 |