Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- struct pair
- {
- int first,second;
- };
- struct pair ara[1000];
- void sort(int n)
- {
- for(int i=0;i<n;i++)
- {
- for(int j=i+1;j<n;j++)
- {
- if(ara[i].first>ara[i].second)
- {
- struct pair temp=ara[i];
- ara[i]=ara[j];
- ara[j]=temp;
- }
- }
- }
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- for(int i=0;i<n;i++)
- {
- scanf("%d",&ara[i].first);
- ara[i].second=i+1;
- }
- int khujo;
- scanf("%d",&khujo);
- sort(n);
- int lo=0;
- int hi=n-1;
- int mid;
- while(hi>=lo)
- {
- mid=(hi+lo)/2;
- if(ara[mid].first==khujo)
- {
- printf("%d number jaygay pawa gese :D",ara[mid].second);
- return 0;
- }
- else if(ara[mid].first>khujo) hi=mid-1;
- else lo=mid+1;
- }
- printf("pai nai :(");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement