백준
[1157] 단어 공부
Jcoder
2018. 7. 14. 13:07
#include <iostream>#include <string>#include <map>using namespace std;int main(){map<char, int> m;string str;cin >> str;map<char, int>::iterator iter;for (int i = 0; i < str.size(); i++){if (str[i] >= 'a'){str[i] -= 32;}//기존에 존재 하는 값인지 검사.iter = m.find(str[i]);if (iter != m.end()) //존재할때m[iter->first] += 1;else //존재하지 않을때m[str[i]] = 1;}//횟수가 가장 많은 값을 가리키는 반복자를 찾습니다map<char, int>::iterator max = m.begin();iter = m.begin()++;for (; iter != m.end(); iter++){if (max->second < iter->second)max = iter;}//max인 횟수와 같은 횟수가 존재하고, 그 인자의 key가 동일한지 검사합니다.for (iter = m.begin(); iter != m.end(); iter++){if (max->second == iter->second && max->first != iter->first){cout << "?\n";return 0;}}cout << max->first << endl;;return 0;}