백준 #1157 문제

Hansol Lee·2021년 7월 25일
0

백준

목록 보기
4/10

백준 1157 문제 풀이

문제:
https://www.acmicpc.net/problem/1157

풀이:#include <iostream.>
#include

using namespace std;

int alphabet[26] = { 0 };

int main() {
char answer;
string str;
cin >> str;
int most = 0;
int loc;
for (int i = 0; i < str.size(); i++)
{
	if (str[i] < 91)
	{
		alphabet[str[i] - 65]++;
	}
	else
	{
		alphabet[str[i] - 97]++;

	}
}
for (int i = 0; i < 26; i++)
{
	if (most < alphabet[i])
	{
		most = alphabet[i];
		loc = i;
	}

}
for (int i = 0; i < 26; i++)
{
	if (loc != i)
	{
		if (most == alphabet[i])
		{
			cout << "?";
			return 0;

		}
	}
}
answer = loc + 65;
cout << answer;
return 0;

}

profile
얼레벌레 항상 성장하고 싶은 컴공생입니다

0개의 댓글