Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void cekin1( int arr[], int down, int up)
- {
- int pisah,temp,i;
- pisah = up;
- for(i=down;i<pisah;i++)
- {
- if(arr[i]>arr[pisah])
- {
- temp= arr[i];
- arr[i]=arr[pisah-1];
- arr[pisah-1]=arr[pisah];
- arr[pisah]=temp;
- i--;pisah--;
- }
- }
- if(pisah-1-down>0)cekin1(arr,down,pisah-1);
- if(up-(pisah+1)>0)cekin1(arr,pisah+1,up);
- }
- int main()
- { int n;
- int j,z,tut,i,m,target, start,counter;
- char tanda;
- scanf("%d",&n);
- int arr[n+1];
- for(i=0;i<n;i++)
- {
- scanf("%d", &arr[i]);
- }
- // for(z=0;z<n;z++)
- // {
- // printf("%d",arr[z]);
- // } printf("\n");
- //
- cekin1(arr,0,n-1);
- scanf(" %c", &tanda);
- scanf("%d",&m);
- // for(z=0;z<n;z++)
- // {
- // printf("%d",arr[z]);
- // } printf("\n");
- for(j=0;j<m;j++)
- { counter=-1;
- // getchar();
- scanf("%d",&target);
- if(tanda=='d')
- {tut=0;
- for(start=n-1;start>=0;start--)
- {
- //printf("%d_",arr[start]);
- if(arr[start]==target)
- {
- tut++;
- counter=tut;
- break;
- } else
- tut++;
- }
- } else
- {
- for(start=0;start<n;start++)
- {
- //printf("%d_",arr[start]);
- if(arr[start]==target){
- counter=start+1;
- break;}
- }
- }
- printf("%d\n",counter);
- //if(counter==1)continue;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement