Advertisement
Guest User

Untitled

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