Here is my code, but it shows "asd 2" instead of "qwe 3". Why is that?
#include
#include
#include
#include
using namespace std;
int main()
{
string str[8] = {"zxc", "zxc", "asd", "qwe", "qwe", "asd", "qwe", "jkl"};
vector v_str;
string t_str, maxstring;
int maxrep = 1;
int currep = 1;
for(int i = 0; i < 8; i++)
v\_str.push\_back(str\[i\]);
sort(v\_str.begin(), v\_str.end());
t\_str = v\_str\[0\];
maxstring = t\_str;
for(int i = 1; i < v\_str.size(); i++)
{
if(t\_str == v\_str\[i\])
currep++;
else
{
if(currep > maxrep)
{
maxrep = currep;
maxstring = t\_str;
}
t\_str = v\_str\[i\];
currep = 0;
}
}
for(int i = 0; i < v\_str.size(); i++)
cout << v\_str\[i\] << endl;
cout << endl;
cout << maxstring << " " << maxrep << endl;
return 0;
}