练习5.14

编写一段程序,从标准输入中读取若干string对象并查找连续重复出现的单词。所谓连续重复出现的意思是:一个单词后面紧跟着这个单词本身。要求记录连续重复出现的最大次数以及对应的单词。如果这样的单词存在,输出重复出现的最大次数:如果不存在,输出起跳信息说明任何单词都没有连续出现过。例如,如果输入是
 how now now now Brown cow cow

那么输出应该表明单词now连续输出了3次



#include <iostream>
using namespace std;
int main()
{
    string str;
    string str1;
    int count;
    int max=1;
    if(cin>>str){
        str1=str;
    }
    while(cin>>str){
        if(str==str1){
            count++;
            if(max<count){
                max=count;
            }
        }
        else{
            str1=str;
            count=1;
        }
        }
    if(max>1)
    cout<<max<<endl;
    else
    cout<<"无重复"<<endl;
    return 0;
}

posted @ 2014-12-25 15:24  Song_4  阅读(163)  评论(0)    收藏  举报