1071 Speech Patterns (25 分) 注:map映射
#include <stdio.h>
#include <map>
#include <iostream>
#include <string>
int check(char);
using namespace std;
map<string,int>mp;
int main ()
{
int i=0,max=-1;
string str,k;
getline(cin,str);
while (i<str.length())
{
string word="";
while (i<str.length()&&check(str[i])==1)
{
if (str[i]>='A'&&str[i]<='Z')
str[i]+=32;
word=word+str[i];
i++;
}
if (word!="")
{
if (mp.find(word)!=mp.end())
mp[word]++;
else
mp[word]=1;
}
if (i<str.length()&&check(str[i])==0)
i++;
}
map<string,int> :: iterator it;
for (it=mp.begin();it!=mp.end();it++)
{
if (it->second>max)
{
max=it->second;
k=it->first;
}
}
cout<<k<< ' '<<max;
return 0;
}
int check (char c)
{
if (c>='0'&&c<='9')
return 1;
if (c>='a'&&c<='z')
return 1;
if (c>='A'&&c<='Z')
return 1;
return 0;
}
|