본문 바로가기

BOJ

[백준] 1157번 단어공부 c++

#include <iostream>
using namespace std;

int main(void) {
	ios::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);
	int count = 0;
	int arr[26] = { 0, };
	string word;
	int max = 0;
	cin >> word;

	for (int i = 0; i < word.length(); i++) {
		if (word[i] >= 'A' && word[i] <= 'Z')arr[word[i] - 'A']++;
		else arr[word[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (arr[i] >= max) max = arr[i];
	}
	for (int i = 0; i < 26; i++) {
		if (arr[i] == max) count++;
	}

	if (count > 1) cout << '?';
	else {
		for (int i = 0; i < 26; i++) {
			if (arr[i] == max) {
				cout << (char)('A' + i);
			}
		}
	}
	return 0;
}

'BOJ' 카테고리의 다른 글

[백준] 2908번 상수 c++  (0) 2020.04.26
[백준] 1152번 단어의 개수 c++  (0) 2020.04.26
[백준] 8958번 OX퀴즈 c++  (0) 2020.04.26
[백준] 10996번 별 찍기 -21 c++  (0) 2020.04.26
[백준] 1110번 더하기 사이클 c++  (0) 2020.04.26