근본없는 코딩

[C++] 백준1157 단어공부 본문

✔ Online Judge

[C++] 백준1157 단어공부

근본없는 개발자 2023. 6. 29. 23:54

 

#include <iostream>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int cnt[30] = { 0 }, maxCnt = 0, overlap=0;
	char str[1000005], maxChar;
	
	cin >> str;
	for (int i = 0; i < 1000001; i++) {
		if (str[i] == '\0') break;
		if (str[i] >= 'a' && str[i] <= 'z') cnt[str[i] - 'a']++;
		else cnt[str[i] - 'A']++;
	}
	for (int i = 0; i < 26; i++) {
		if (maxCnt < cnt[i]) {
			maxCnt = cnt[i];
			maxChar = char(i + 'A');
			overlap = 0;
		}
		else if (maxCnt == cnt[i] && cnt[i] != 0) {
			overlap++;
		}
	}
	if (overlap == 0) cout << maxChar << '\n';
	else cout << '?' << '\n';
	return 0;
}