个人觉得就是考察STL
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
char save[maxn];
string S[maxn];
int Scount=0;
char Str[maxn];
map<string,int>Map;
stringstream stream;
int cmp(const string &str1,const string &str2)
{
return str1 > str2;
}
bool isword(int i){
if(Str[i] != ' ' && Str[i] != '.' && Str[i] != ',') return true;
return false;
}
int getMap(){
string a,b;
stream.clear();
stream << save;
stream >> a >> b;
string in = a + " " + b;
S[Scount++] = in;
++Map[in];
stream.clear();
memset(save,0,sizeof(save));
stream << b;
stream >> save;
return b.length();
}
void slove(){
sort(S,S+Scount,cmp);
int ans = 0;
int index = -1;
//for(int i = 0;i < Scount; i++) cout<<S[i]<<endl;
for(int i = 0;i < Scount; i++){
if(ans <= Map[ S[i] ]){
ans = Map[ S[i] ];
index = i;
}
}
cout<<S[index]<<":"<<ans<<endl;
}
int main()
{
while(gets(Str)){
int len = strlen(Str);
if(Str[0] == '#'){
slove();
Scount=0;
for(int i=0;i<maxn;i++) S[i].clear();
Map.clear();
continue;
}
int words=0,space=0;
int Count=0;
memset(save,0,sizeof(save));
for(int i = 0; i < len; i++){
if(isword(i)) {
if(words == 1) save[Count++] = ' ';
++words;
for(int j = i;isword(j) && j<len;j++){
save[Count++] = Str[j];
i = j;
}
//cout<<save<<"***"<<i<<endl;
//cout<<words<<"****"<<space<<endl;
//system("pause");
}
else{
if(Str[i] == '.' || Str[i] == ',') {
Count = 0;
words = 0;
space = 0;
memset(save,0,sizeof(save));
}
else{
for(int j = i;Str[j]==' ' && j<len;j++){
i = j;
}
++space;
}
}
if(space == 1 && words == 2){
words = 1;
space = 0;
//cout<<save<<endl;
Count = getMap();
//cout<<save<<endl;
//system("pause");
}
}
memset(Str,0,sizeof(Str));
}
return 0;
}