Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- // freopen("in.txt", "r", stdin);
- // freopen("Out.txt", "w", stdout);
- int a[10000];
- int n;
- scanf("%d", &n);
- for(int i=0;i<n;i++)
- scanf("%d", &a[i]);
- // cout<<"The number, you want to find out: ";
- int key;
- scanf("%d", &key);
- int l=0;
- int h=n-1;
- int mid;
- int temp=0;
- int idx;
- while(l<=h){
- mid=(l+h)/2;
- if(a[mid]==key){
- idx=mid;
- h=mid-1;
- temp=1;
- }
- else if(a[mid]<key){
- l=mid+1;
- }
- else{
- h=mid-1;
- }
- }
- printf("index=%d\n", idx);
- if(temp!=1)
- printf("Paini :/\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement