Răspuns:
#include <iostream>
using namespace std;
int n,m,i, x[25001], num;
int div_imp (int p, int q)
{
int mij;
if (q<p)
return 0;
else
{
mij=(p+q)/2;
if(x[mij]==num)
return 1;
else
if(num<x[mij])
return div_imp (p, mij-1);
else
return div_imp (mij+1,q);
}
}
int main()
{
cin >> n;
for (i=0; i<n; ++i)
cin >> x[i];
cin >> m;
for (i=1; i<=m; ++i)
{
cin >> num;
if (div_imp(0,n-1))
cout << 1;
else cout << 0;
cout << " ";
}
}
Explicație: