/*
模擬題,混用c和c++了,代碼比較亂。
ps:"alphanumercial" mean that f4 is a word.
*/
#include<iostream>
#include<string>
#include<string.h>
#include<map>
using namespace std;
char str[1050000];
char ctmp[1050000];
map<string,int>mp;
map<string,int>::iterator it;
int main(){
int i,j,s,e;
gets(str);
int flag1=1,flag2=1;
for(i=0;str[i]!='\0';i++){
if('A'<=str[i]&&str[i]<='Z')
str[i]=str[i]-'A'+'a';
}
int len=strlen(str);
str[len]='!';//add this input hello will be right.
str[len+1]='\0';
s=0;
string stmp;
for(i=s;str[i]!='\0';){
if(('0'<=str[i]&&str[i]<='9')||('a'<=str[i]&&str[i]<='z')){
i++;
}
else{
int k=0;
for(j=s;j<i;j++){
ctmp[k]=str[j];
k++;
}
ctmp[k]='\0';
stmp=ctmp;
mp[stmp]++;
for(j=i;str[j]!='\0';j++){
if((('0'<=str[j]&&str[j]<='9')||('a'<=str[j]&&str[j]<='z')))
break;
}
s=j;
i=j;
}
}
if(mp.size()==0){
}
else{
string ans;
int intmax=0;
for(it=mp.begin();it!=mp.end();it++){
if(it->second>intmax){
intmax=it->second;
ans=it->first;
}
}
cout<<ans<<" "<<intmax<<endl;
}
return 0;
}
浙大PAT 1071題 1071. Speech Patterns
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.