-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1302.cpp
49 lines (45 loc) · 818 Bytes
/
1302.cpp
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
// 1302. 베스트셀러
// 2020.03.29
// 정렬, 탐색
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
int n;
cin >> n;
map<string, int> lib;
while (n-- > 0)
{
string s;
cin >> s;
if (lib.find(s) == lib.end())
{
lib[s] = 1;
}
else
{
lib[s]++;
}
}
int maxCount = -1;
string ans = "{";
for (auto name : lib)
{
if (name.second > maxCount)
{
maxCount = name.second;
ans = name.first;
}
else if (name.second == maxCount)
{
if (name.first.compare(ans) == -1)
{
ans = name.first;
}
}
}
cout << ans << endl;
return 0;
}