-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab_8.cpp
More file actions
35 lines (26 loc) · 746 Bytes
/
Copy pathLab_8.cpp
File metadata and controls
35 lines (26 loc) · 746 Bytes
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
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
int main() {
vector<int> sightings;
int num;
while (cin >> num) {
sightings.push_back(num);
}
unordered_map<int, int> freq;
for (int plant : sightings) {
freq[plant]++;
}
int maxFreq = 0;
int result = 0;
for (auto& [plant, count] : freq) {
if (count > maxFreq || (count == maxFreq && plant < result)) {
maxFreq = count;
result = plant;
}
}
cout << result << endl;
return 0;
}