编写一个小程序,从标准输入读入一系列string对象,寻找连续重复出现的单词。程序应该找出满足一下条件的单词:该单词的后面紧接着再次出现自己本身。跟踪重复次数最多的单词及其重复次数,输出.

来源:互联网 发布:剑雨江湖宠物进阶数据 编辑:程序博客网 时间:2024/06/07 07:43
#include <iostream>
#include <string>

using namespace std;


int main( )
{
string nowword, beforeword, result;
int count, maxCount;
cin>>nowword;
result = beforeword = nowword;
count = maxCount = 1;
while(cin>>nowword)
{
if(nowword == "quit")
break;
if(nowword == beforeword)
count++;
else
{
beforeword = nowword;
count = 1;
}
if(count > maxCount)
{
result = nowword;
maxCount = count;
}

}
cout<<maxCount<<result;
return 0;
}


原创粉丝点击