-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1157.cpp
More file actions
58 lines (49 loc) · 1.1 KB
/
Copy path1157.cpp
File metadata and controls
58 lines (49 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <unordered_map>
#include <string>
#include <cctype>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string word;
cin >> word;
unordered_map<char, int> charCount;
for (char ch : word)
{
if (islower(ch))
{
ch = toupper(ch);
}
charCount[ch]++;
}
char result = '?';
int maxCount = 0;
bool isDuplicate = false;
for (const auto& entry : charCount)
{
// entry.first는 키이다. 즉, 여기서는 char 타입의 단어의 문자
// entry.second는 값이다. 즉, 여기서는 char의 등장 횟수
if (entry.second > maxCount)
{
maxCount = entry.second;
result = entry.first;
isDuplicate = false;
}
else if (entry.second == maxCount)
{
isDuplicate = true;
}
}
if (isDuplicate)
{
cout << "?";
}
else
{
cout << result;
}
return 0;
}