fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int v[50],n,x;
  6. cin>>n>>x;
  7. for(int i=0;i<n;i++)
  8. {
  9. cin>>v[i];
  10. }
  11. int st=0,dr=n-1,mij,gasit=-1;
  12. while(st<=dr){
  13. mij=(st+dr)/2;
  14. if(v[mij]==x){
  15. gasit=mij;
  16. break;
  17. }
  18. else
  19. if(x<v[mij]){
  20. dr=mij-1;
  21. }
  22. else if(x>v[mij])
  23. st=mij+1;
  24. }
  25. cout<<gasit;
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5320KB
stdin
5 7
1 3 5 7 9
stdout
3