I am trying to solve a problem and i am pretty sure the code works. However it turns out that when passing by this part
int x = it->second;
if ( x > max);
{
f = it->first;
max = it->second;
}
it skips immediately to the if block without checking the condition , some help please?
here is the full code
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
using namespace std;
int main(){
int n;
cin >> n;
map<string, int> m;
string s;
for (int i = 0; i < n; i++)
{
cin >> s;
m[s]++;
}
string f;
int max = -1;
map<string,int>::iterator it;
for (it=m.begin(); it!=m.end(); it++)
{
int x = it->second;
if ( x > max);
{
f = it->first;
max = it->second;
}
}
cout << f << endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire