#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
string temp;
vector<string> encrypt, decrypt;
int i,n, co=0;
cin >> n;
for(i=0;i<n;i++)
{
cin >> temp;
encrypt.push_back(temp);
}
for(i=0;i<n;i++)
{
cin >> temp;
decrypt.push_back(temp);
}
for(i=0;i<n;i++)
{
temp = encrypt[i];
if((binary_search(decrypt.begin(), decrypt.end(), temp)) == true) ++co;
}
cout << co << endl;
return 0;
}
It reads two equal lists of strings and should print out how many of the words in the first list are also found in the second list, simple.
Not giving me the expexted results and i think the problem is in binary_search.
Can you tell me why ?
Because the strings are not sorted in your vectors. Sort them first using
std::sort.