1071 Speech Patterns (25 分)(******)
程序员文章站
2024-02-16 13:04:22
...
#include <iostream>
#include <cstdio>
#include <map>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;
bool wetherQ(char a)
{
if(a <= 'z' && a >= 'a') return true;
if(a <= 'Z' && a >= 'A') return true;
if(a <= '9' && a >= '0') return true;
return false;
}
int main()
{
map<string,int>mp;
string s;
getline(cin,s);
int i = 0;
while(i<s.length())
{
string word;
while(i<s.length() && wetherQ(s[i]) == true)
{
char ll = s[i];
if(s[i] <= 'Z' && s[i] >= 'A')
s[i] += 'a' - 'A';
word += s[i++];
}
if(word != "")
{
mp[word]++;
}
while(i<s.length() && wetherQ(s[i]) == false)
i++;
}
map<string,int>::iterator it;
string ans1;
int ans2 = -1;
for(it = mp.begin();it!=mp.end();it++)
{
if(ans2 < it->second)
{
ans2 = it->second;
ans1 = it->first;
}
}
cout<<ans1<<" "<<ans2;
return 0;
}
上一篇: 决策树算法及python实现