fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 50000;
  5.  
  6. int main() {
  7. int n, arr[MAX_SIZE + 1];
  8. cin >> n;
  9. for (int i = 1; i <= n; ++i) {
  10. cin >> arr[i];
  11. }
  12. int m;
  13. cin >> m;
  14. int x;
  15. for (int j = 1; j <= m; ++j) {
  16. cin >> x;
  17. int left = 1, right = n, firstPosition = -1;
  18. while (left <= right) {
  19. int mid = left + (right - left) / 2;
  20. if (arr[mid] == x) {
  21. firstPosition = mid;
  22. right = mid - 1;
  23. } else if (arr[mid] < x) {
  24. left = mid + 1;
  25. } else {
  26. right = mid - 1;
  27. }
  28. }
  29. if (firstPosition != -1) {
  30. cout << x << " se gaseste in sir" << "\n";
  31. } else {
  32. cout << x << " nu se gaseste in sir" << "\n";
  33. }
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5284KB
stdin
7
5 12 15 17 20 2 4
4
1 15 5 7
stdout
1 nu se gaseste in sir
15 se gaseste in sir
5 se gaseste in sir
7 nu se gaseste in sir