#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cctype>
#include <string>
#include <iostream>
using namespace std;
const int N = 1048576;
int main(void) {
map<string, int> mp;
map<string, int>::iterator it;
char *word = new char[N], tmp;
int i = 0, cnt = -1;
string str, maxstr;
do {
scanf("%c", &tmp);
if (isalpha(tmp) || isdigit(tmp)) {
word[i] = tolower(tmp);
i++;
}
else if(i) {
word[i] = '\0';
i = 0;
str = string(word);
it = mp.find(str);
if (it == mp.end()) {
mp[str] = 1;
if (cnt < 1) {
cnt = 1;
maxstr = str;
}
else if(cnt == 1) {
if (str < maxstr) {
maxstr = str;
}
}
}
else {
mp[str]++;
if (mp[str] > cnt) {
cnt = mp[str];
maxstr = str;
}
else if (mp[str] == cnt) {
if (str < maxstr) {
maxstr = str;
}
}
}
}
} while (tmp != '\n');
cout << maxstr << ' ' << cnt << endl;
delete[] word;
return 0;
}
1071. Speech Patterns (25)解题报告
最新推荐文章于 2024-11-18 20:54:57 发布
