초고교급 희망

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

Algorithm/Baekjoon

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

연모링 2021. 7. 8. 12:34
728x90

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

int main()
{
	int max = 0, index = 0, arr[26] = {};
	int count = 0;
	string S;
	const string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	cin >> S;
	
	//대소문자 변환
	for (int i = 0; i < S.length(); i++)
	{
		S[i] = toupper(S[i]);
		arr[a.find(S[i])]++;
	}

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

}

 

728x90

'Algorithm > Baekjoon' 카테고리의 다른 글

[백준][C++]2805번 나무 자르기  (0) 2022.05.16
[백준][C++]1072번 게임  (0) 2022.05.16
[백준][Python]10866 0 = not cute / 1 = cute  (0) 2021.08.07
[백준][C++]2908번 상수  (0) 2021.07.09
[백준][C++] 4673번 셀프 넘버  (0) 2021.06.30