백준 1269 c++

magicdrill·2024년 2월 26일
0

백준 문제풀이

목록 보기
30/655

백준 1269 c++

#include <iostream>
#include <cstring>

using namespace std;

int main(void)
{
	char* str = new char[1000001];
	int i, j, len, temp, max = 0, maxcount = 1;
	int count[26] = { 0 };
	char res;

	cin >> str;
	if ((int)strlen(str) <= 1000000)
	{
		len = (int)strlen(str);
		for (i = 0; i < len; i++)
		{
			if ((int)str[i] >= 97 && (int)str[i] <= 122)
			{
				str[i] = (int)str[i] - 32;
			}
			else
			{
				;
			}
		}
		for (i = 0; i < len; i++)
		{
			for (j = 0; j < sizeof(count) / sizeof(count[0]); j++)
			{
				if (((int)str[i] - 65) == j)
				{
					temp = count[j];
					temp++;
					count[j] = temp;
					break;
				}
				else
				{
					;
				}
			}
		}
		for (i = 0; i < sizeof(count) / sizeof(count[0]); i++)
		{
			if (count[i] > max)
			{
				maxcount = 1;
				max = count[i];
				res = i + 65;
			}
			else if(count[i] == max)
			{
				maxcount++;
			}
			else
			{
				;
			}
		}
		if (maxcount == 1)
		{
			cout << res << endl;
		}
		else
		{
			cout << '?' << endl;
		}
	}
	else
	{
		;
	}
	return 0;
}

0개의 댓글