-
Notifications
You must be signed in to change notification settings - Fork 0
/
1071 Speech Patterns.cpp
53 lines (53 loc) · 1.3 KB
/
1071 Speech Patterns.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
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(string a, string b){
int i = 0, j = 0;
while(i < a.size() && j < b.size()){
if(isdigit(a[i])){
i++;
continue;
}
if(isdigit(b[j])){
j++;
continue;
}
if(a[i] != b[i])
return a[i] < b[i];
}
return 1;
}
int main(){
string tmp = "";
map<string, int> m;
char c = getchar();
while(c != '\n'){
if(isdigit(c) || isalpha(c)){
if(c >= 'A' && c <= 'Z')
c += 'a' - 'A';
tmp += c;
}
else if(tmp.size() > 0){
m[tmp]++;
tmp = "";
}
c = getchar();
}
if(tmp.size() > 0)
m[tmp]++; //粗心!!!!!!!!
int mx = -1;
vector<string> ans;
for(auto it = m.begin(); it != m.end(); it++){
if(it->second > mx){
mx = it->second;
ans.clear();
ans.push_back(it->first);
}
else if(it->second == mx)
ans.push_back(it->first);
}
sort(ans.begin(), ans.end(), cmp); // 这里不排序也能AC,但是按照题目要求应该是要排序的
cout << ans[0] << " " << m[ans[0]];
}