现在的位置: 首页 > 综合 > 正文

浙大PAT 1071题 1071. Speech Patterns

2018年02月06日 ⁄ 综合 ⁄ 共 894字 ⁄ 字号 评论关闭
/*
模拟题,混用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;
}

抱歉!评论已关闭.