-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1071.cpp
More file actions
38 lines (37 loc) · 726 Bytes
/
1071.cpp
File metadata and controls
38 lines (37 loc) · 726 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
36
37
#include <bits/stdc++.h>
using namespace std;
struct node{
string key;
int freq;
node(string s, int f){
key = s;
freq = f;
}
friend bool operator<(const node &a, const node &b){
return a.freq != b.freq ? a.freq > b.freq : a.key < b.key;
}
};
int main(){
ios::sync_with_stdio(false);
map<string, int> mp;
set<node> st;
string in, word = "";
getline(cin, in);
transform(in.begin(), in.end(), in.begin(), ::tolower);
for(int i=0; i<=in.size(); i++){
if(i==in.size() || !isalnum(in[i])){
mp[word]++;
word = "";
}else{
word += in[i];
}
}
for(auto it : mp){
if(it.first != ""){
st.insert(node(it.first, it.second));
}
}
auto it = st.begin();
cout<<it->key<<' '<<it->freq;
return 0;
}