#include <iostream>
#include <string>
int main()
{
using namespace::std;
string temp(""), nowWord(""),wordMax("");
unsigned maxCnt(0), Cnt(0);
while (cin >> temp)
{
if (temp == nowWord)
{
++Cnt;
if (Cnt > maxCnt)
{
maxCnt = Cnt;
wordMax = nowWord;
}
}
else
{
nowWord = temp;
Cnt = 1;
}
}
if(maxCnt>1)
cout << "Word:" << wordMax << " occurs " << maxCnt << " times.";
else
cout << "No word has occured more than two times.";
return 0;
}
C++ Primer练习5.14解答
最新推荐文章于 2022-07-09 15:41:20 发布