RabbitVoting
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class RabbitVoting
{
public:
string getWinner( vector <string> names, vector <string> votes );
};
string RabbitVoting::getWinner( vector <string> names, vector <string> votes )
{
int n = (int)names.size();
vector<int> obtain( n );
for ( int i=0; i<n; i++ )
if ( votes[i] != names[i] )
for ( int j=0; j<n; j++ )
if ( votes[i] == names[j] )
obtain[j]++;
int m = *max_element( obtain.begin(), obtain.end() );
if ( count( obtain.begin(), obtain.end(), m ) > 1 )
return "";
else
return names[ find(obtain.begin(),obtain.end(),m) - obtain.begin() ];
}