Write a program to read strings from standard input looking for duplicated words. The program should find places in the input where one word is followed immediately by itself. Keep track of the largest number of times a single repetition occurs and which word is repeated.
Print the maximum number of duplicates, or else print a message saying that no word was repeated. For example, if the input is
how now now now brown cow cow
the output should indicate that the word now occurred three times.
string s;
vector<string> vs;while (cin>>s)
{
vs.push_back(s);
}
auto beg=vs.begin();
string prevStr=*beg;
string mostStr;
int maxCount=0,count=0;
for (;beg!=vs.end() ;++beg )
{
if (prevStr==*beg)
{
++count;
}
else
count=1;
if (count>maxCount)
{
maxCount=count;
mostStr=prevStr;
}
prevStr=*beg;
}
cout<<maxCount<<" times "<<mostStr<<" occurs"<<endl;