Advertisement
nicuvlad76

Untitled

Nov 19th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #define N 25005
  4. using namespace std;
  5. //ifstream fin ("eratostene1.in");
  6. //ofstream fout ("eratostene1.out");
  7. int n,i,m;
  8. int a[N],x;
  9. int st, dr, mij;
  10. bool gasit;
  11. int main()
  12. {
  13. cin>>n;
  14. for(i=1;i<=n;++i)
  15. cin>>a[i];
  16. cin>>m;
  17. while(m>0)
  18. {
  19. --m;
  20. cin>>x;///valorea de cautat
  21. ///cautarea binara
  22. /* st=1, dr=n;
  23. gasit=0;
  24. while(st<=dr && !gasit)
  25. {
  26. mij=(st+dr)/2;///mij=st+(dr-st)/2;
  27. if(x==a[mij]) gasit=1;
  28. else if(x>a[mij]) st=mij+1;
  29. else dr=mij-1;
  30. }*/
  31. gasit=binary_search(a+1,a+n+1,x);
  32. cout<<gasit<<" ";
  33. }
  34. return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement