pku 1583 Choose Your Words Carefully
这题是不区分大小写的
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <string>
#include <map>
#include <iostream>
using namespace std;
#define WLEN 85
string in;
map<string,int> text;
char buf[WLEN];
int main()
{
char ch;
int i,j,t,max=0;
while( (ch=getchar()) !=EOF )
{
i=0;
while( ch!=EOF && !isalpha(ch) && (ch=getchar()) ) ;
buf[i++]=ch;
while( ch!=EOF && (ch=getchar() )!=EOF && isalpha(ch) )
{
if(ch==EOF) break;
buf[i++]=ch;
}
buf[i]=0;
for(j=0;j<i;j++)
if(buf[j]>='A' && buf[j]<='Z')
buf[j]+=32;
in.assign(buf);
t=++text[buf];
if(t>max) max=t;
if(ch==EOF) break;
}
cout<<max<<" occurrences"<<endl;
map<string,int>::const_iterator iter;
for(iter=text.begin();iter!=text.end();iter++)
{
if(iter->second==max)
cout<<iter->first<<endl;
}
return 0;
}
浙公网安备 33010602011771号