#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int num = 1;//计数
string word;//输入及记录单词
vector<string> vec;//储存文章
while (cin>>word && word[0] != '0')
{
vec.push_back(word);
}
vector<string>::iterator iter1 = vec.begin();
vector<string>::iterator iter2 = vec.begin();
word = *iter2++;
while(iter2 != vec.end())
{
if (*iter1++ == *iter2++)
if (*iter1 == word)
++num;
else
{
int fnum = 2;
while (*iter1 == *iter2 && iter2 != vec.end())
{
++fnum;
++iter1;
++iter2;
}
if(fnum >= num)
{
word = *iter1;
num = fnum;
}
}
}
cout << word << "连续出现了" << num << "次" <<endl;
return 0;
}
--------------------VC++6.0编译-------------------------------------------------
输入:a a a b b b b a a a c c c c c b 0
打印:c连续出现了5次
--------------------------------------------------------------------------------
为什么把
using namespace std;
换成
using std::string;
using std::vector;
using std::iterator;
using std::cin;
using std::cout;
using std::endl;
会出错