-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maximum_frequency.cpp
54 lines (46 loc) · 1017 Bytes
/
Maximum_frequency.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
50
51
52
53
54
#include<iostream>
#include<unordered_map>
#include<list>
#include<vector>
#include<climits>
#include<unordered_set>
#include<queue>
#include<stack>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
#define mp make_pair
#define INFI 10e8
#define INF 10e7
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
void max_frequency(string s){
unordered_map<char, int> my_map;
for(int i = 0; i < s.size(); i++){
if(my_map.count(s[i]) > 0){
my_map[s[i]]++;
}
else{
my_map[s[i]] = 1;
}
}
pair<char, int> p('\0', INT_MIN);
for(auto character : my_map){
if(character.second >= p.second){
p.first = character.first;
p.second = character.second;
}
}
cout << p.first << '\n';
}
int main(){
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
max_frequency(s);
}