MohamedAbdel3al

searching

Jul 26th, 2021
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std ;
  4. typedef long long ll ;
  5. int main() {
  6. ios::sync_with_stdio(false) ; cout.tie(NULL) ; cin.tie(NULL) ;
  7.  
  8. int n , pos = 0 ;
  9. bool p = false ;
  10. cin >> n ;
  11. ll arr[n] , num ;
  12. for (int i = 0; i < n; i++) cin >> arr[i] ;
  13. cin >> num ;
  14. for (int i = 0; i < n; i++) {
  15. if (arr[i] == num)
  16. p = true ;
  17. pos = i ;
  18. break;
  19. }
  20. if (p == true) cout << -1 ;
  21. else cout << pos ;
  22.  
  23. return 0;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment