-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathA1071-2.cpp
More file actions
41 lines (39 loc) · 784 Bytes
/
A1071-2.cpp
File metadata and controls
41 lines (39 loc) · 784 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
38
39
40
41
#include <iostream>
#include <string>
#include <map>
using namespace std;
bool check(const char &c){
if(c >= '0' && c <= '9') return true;
else if(c >= 'A' && c <='Z') return true;
else if(c >= 'a' && c <='z') return true;
return false;
}
int main(){
map<string, int> cnt;
string str;
getline(cin, str);
int i = 0;
while(i < str.length()){
string word;
while(i < str.length() && check(str[i]) == true){
word += tolower(str[i]);
++i;
}
if(word.length() > 0){
++cnt[word];
}
while(i < str.length() && check(str[i]) == false){
++i;
}
}
string ans;
int max = 0;
for(map<string, int>::iterator it = cnt.begin(); it != cnt.end(); ++it){
if(it->second > max){
ans = it->first;
max = it->second;
}
}
cout << ans << " " << max;
return 0;
}