Advertisement
nicuvlad76

Untitled

Nov 26th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #define N 25005
  3. using namespace std;
  4. //ifstream fin(".in");
  5. //ofstream fout(".out");
  6.  
  7. int a[N],n,m,x;
  8.  
  9. void Citire()///procedurala
  10. {
  11. cin>>n;
  12. for(int i=1;i<=n;i++)
  13. cin>>a[i];
  14. }
  15.  
  16. bool CautBinar(int st, int dr, int x)///functie operator
  17. {
  18. int mij;
  19. while(st<=dr)
  20. {
  21. mij=(st+dr)/2;
  22. if(a[mij]==x) return 1;
  23. else if(a[mij]<x) st=mij+1;
  24. else dr=mij-1;
  25. }
  26. return 0; ///valoare de returnat
  27. }
  28.  
  29. void Afisare() ///procedural
  30. {
  31. cin>>m;
  32. for(int i=1;i<=m;i++)
  33. {
  34. cin>>x;
  35. cout<<CautBinar(1,n,x)<<" ";///apel functie operator
  36. }
  37. }
  38.  
  39. int main()
  40. {
  41. Citire();///apelul functie
  42. Afisare();
  43. return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement