binary_search not working for a vector<string>
Posted
by VaioIsBorn
on Stack Overflow
See other posts from Stack Overflow
or by VaioIsBorn
Published on 2010-03-24T19:43:20Z
Indexed on
2010/03/24
19:53 UTC
Read the original article
Hit count: 248
#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 ?
© Stack Overflow or respective owner