相邻重复字符数目最大者

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <bitset>

using namespace std;

int main()
{
    string str,prestr,restr;
    int cnt=0,max=1;
    while (cin>>str)
    {
        if (prestr==str)
        {
            ++cnt; 
        } 
        else
        {
            if (cnt>max)
            {
                restr=prestr;
                max=cnt;
            }
            cnt=1;
        }
        prestr=str;
    }
    if (max<cnt)
    {
        max=cnt;
        restr=str;
    }
        
    cout<<restr<<max<<endl;
    return 0;
}

 

posted @ 2016-07-15 20:08  随风9  阅读(156)  评论(0编辑  收藏  举报