//6_12.cpp
//从标准输入一系列string对象,寻找连续重复出现的单词
//输入重复次数的最大值,若没有单词重复则输入说明信息
#include<iostream>
#include<string>
using namespace std;
int main(){
string Preword,Curword,Repword;
int Ccount=0,Maxcount=0;//当前重复的单词以及重复的最大次数
cout<<"input word"<<endl;
while(cin>>Curword){
if(Curword==Preword)
Ccount++;
else { //当前单词不是前一单词的重复
if(Maxcount<Ccount){
Maxcount=Ccount;
Repword=Preword;
}
Ccount=1;
}
Preword=Curword;
}
if(Maxcount != 1)
cout<<'"'<<Repword<<'"'<<"repeat for"<<Maxcount
<<"times"<<endl;
else cout<<"no repeat word";
return 0;
}
//从标准输入一系列string对象,寻找连续重复出现的单词
//输入重复次数的最大值,若没有单词重复则输入说明信息
#include<iostream>
#include<string>
using namespace std;
int main(){
string Preword,Curword,Repword;
int Ccount=0,Maxcount=0;//当前重复的单词以及重复的最大次数
cout<<"input word"<<endl;
while(cin>>Curword){
if(Curword==Preword)
Ccount++;
else { //当前单词不是前一单词的重复
if(Maxcount<Ccount){
Maxcount=Ccount;
Repword=Preword;
}
Ccount=1;
}
Preword=Curword;
}
if(Maxcount != 1)
cout<<'"'<<Repword<<'"'<<"repeat for"<<Maxcount
<<"times"<<endl;
else cout<<"no repeat word";
return 0;
}