온라인저지
[BOJ] 1157번: 단어 공부
plzfday
2018. 7. 26. 18:31
https://www.acmicpc.net/problem/1157
소문자, 대문자 구분해서 26칸짜리 배열에 다 집어넣고 가장 많이 있는 인덱스 + 'A' 출력!
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false), cin.tie(0);
string s;
cin >> s;
int al[26] = { 0, };
for (auto &i : s)
{
if ('A' <= i && i <= 'Z')
al[i - 'A']++;
else
al[i - 'a']++;
}
char maxC;
int max = -1;
for (int i = 0; i < 26; ++i)
{
if (max < al[i])
{
max = al[i];
maxC = i + 'A';
}
}
for (int i = 0; i < 26; ++i)
{
if (max == al[i] && maxC - 'A' != i)
{
cout << '?';
return 0;
}
}
cout << maxC;
return 0;
}