Advertisement
dumitreskw

508

Feb 12th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int cautare(int x, int V[], int n){
  4. int st=1, dr=n, mij;
  5. while(st<=dr){
  6. mij=(st+dr)/2;
  7. if(V[mij]==x) return 1;
  8. else {
  9. if(V[mij]>x) dr=mij-1;
  10. else st=mij+1;
  11. }
  12.  
  13. }
  14. return 0;
  15. }
  16.  
  17. int main(){
  18. int n,m,x[25001],y,i;
  19. cin >> n;
  20. for(i=1;i<=n;i++) cin >> x[i];
  21. cin >> m;
  22. for(i=1;i<=m;i++){ cin >> y;
  23. cout << cautare(y,x,n) << " ";
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement