本文主要是介绍浙大PAT 1071题 1071. Speech Patterns,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
/*
模拟题,混用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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!