#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
string s;
vector<string> svec;
while (cin >> s)
svec.push_back(s);
vector<int> max(svec.size());
max[0] = 1;
for (size_t ix = 0; ix != svec.size() - 1; ++ix) {
if (svec[ix] == svec[ix+1])
max[ix+1] = max[ix] + 1;
else
max[ix+1] = 1;
}
int itemp;
string stemp;
for (size_t ix = max.size(); ix != 1; --ix) {
for (size_t iy = 0; iy != ix - 1; ++iy)
if (max[iy] > max[iy + 1]) {
itemp = max[iy]; stemp = svec[iy];
max[iy] = max[iy+1]; svec[iy] = svec[iy+1];
max[iy+1] = itemp; svec[iy+1] = stemp;
}
}
if (max[max.size() - 1] == 1)
cout << "no repeat " << endl;
else {
for (size_t ix = 0; ix != max.size() - 1; ++ix) {
if (max[max.size() - 1] == max[ix])
cout << svec[ix] << " is repeat " << max[ix] << " times" << endl;
}
}
cout << svec[svec.size() - 1] << " is repeat " << max[max.size() - 1] << " times" << endl;
return 0;
}
输入一组string.判断哪个单词输入的连续次数最多
最新推荐文章于 2018-09-11 11:03:35 发布