Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool Cautare(int v[], int st, int dr, int x)
  6. {
  7. if(st==dr)
  8. {
  9. if(v[st]==x)
  10. return 1;
  11. else
  12. return 0;
  13. }
  14. else
  15. {
  16. int mij=(st+dr)/2;
  17. if(v[mij]>=x)
  18. return Cautare(v,st,mij,x);
  19. else
  20. return Cautare(v,mij+1,dr,x);
  21. }
  22. }
  23.  
  24. int n, m, x[25001], y[2000001];
  25.  
  26. int main()
  27. {
  28.  
  29. cin >> n;
  30. for (int i=1; i<=n; i++)
  31. cin >> x[i];
  32. cin >> m;
  33. for (int i=1; i<=m; i++)
  34. cin >> y[i];
  35. for(int i=1;i<=m;i++)
  36. {
  37. int z = Cautare(x,1,n,y[i]);
  38. if(z==1)
  39. cout << 1 << " ";
  40. else
  41. cout << 0 << " ";
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement