-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1071.cpp
64 lines (61 loc) · 1.29 KB
/
1071.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
55
56
57
58
59
60
61
62
63
64
//
// 1071.cpp
// 算法
//
// Created by 王怡凡 on 2017/4/2.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<map>
#include<string>
#include<iostream>
using namespace std;
bool check(char c) {
if(c>='0'&&c<='9') {
return true;
}
if(c>='A'&&c<='Z') {
return true;
}
if(c>='a'&&c<='z') {
return true;
}
return false;
}
int main() {
map<string,int> count;
string str;
getline(cin, str);
int i=0;
while(i<str.length()) {
string word;
while(i<str.length()&&check(str[i])==true) {
if(str[i]>='A'&&str[i]<='Z') {
str[i] += 32;
}
word += str[i];
i++;
}
if(word!="") {
// if(count.find(word)==count.end()) {
// count[word]=1;
// } else {
// count[word]++;
// }
count[word]++;
}
while(i<str.length()&&check(str[i])==false) {
i++;
}
}
string ans;
int max=0;
for(map<string,int>::iterator it=count.begin();it!=count.end();it++) {
if(it->second>max) {
max = it->second;
ans = it->first;
}
}
cout << ans << " " << max << endl;
return 0;
}