Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int j,t,i,m,n,Arr[110],Ub,Lb=0,mid;
- cin>>n;
- for(i=0; i<n; i++)
- {
- cin>>Arr[i];
- }
- Ub=n-1;
- for(i=0; i<n; i++)
- {
- for(j=0 ; j<n-1; j++)
- {
- if(Arr[j]>Arr[j+1])
- {
- t=Arr[j];
- Arr[j]=Arr[j+1];
- Arr[j+1]=t;
- }
- }
- }
- cout<<"Search" << endl;
- cin>>m;
- while(Lb<=Ub)
- {
- mid=(Lb+Ub)/2;
- if(m==Arr[mid])
- {break;}
- else if(m>Arr[mid])
- {
- Lb=mid+1;
- }
- else if (m<Arr[mid])
- {
- Ub=mid-1;
- }
- }
- if(Lb<=Ub)
- cout<<"Yes";
- else
- cout<<"NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement