#include<iostream>
#include<string>
using namespace std;
int main ()
{
string preWord, currWord;
string repWord;
int currCnt = 0,maxCnt = 1;
cout << "Enter sone words(Ctrl+Z to end): " << endl;
while(cin >> currWord)
{
if(currWord == preWord)
++currCnt;
else
{
if(currCnt > maxCnt)
{
maxCnt = currCnt;
repWord = preWord;
}
currCnt = 1;
}
preWord = currWord;
}
if(currCnt > maxCnt){
maxCnt = currCnt;
repWord = currWord;
}
if(maxCnt != 1)
cout << repWord << "重复了" << maxCnt << "次。" << endl;
else
cout << "没有重复的单词. " << endl;
return 0;
}
while 循环3
最新推荐文章于 2023-05-23 10:40:51 发布