Răspuns:
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int x[100];
for (int i=1; i<=n; i++) {
cin >> x[i];
}
int m;
cin >> m;
int y[100];
for (int i=1; i<=m; i++) {
cin >> y[i];
}
int st, dr, mij, poz, gasit;
for (int j=1; j<=m; j++) {
st=1; dr=n; gasit=0;
mij=(st+dr)/2;
if (x[mij]==y[j]) {
gasit=1;
}
while (st<dr && gasit==0) {
if (x[mij]<y[j]) {
st=mij+1;
}
else {
dr=mij-1;
}
mij=(st+dr)/2;
if (x[mij]==y[j]) {
gasit=1;
}
}
if (gasit) cout << 1 << " ";
else cout << 0 << " ";
}
}
Explicație: