您的位置:首页 > 移动开发 > 微信开发

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

2012-11-23 14:00 1031 查看
#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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐