Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. int main()
  5. {
  6.     int N, max=-1000001, max_idx=0, t=0;
  7.     int A[100001];
  8.     scanf("%d", &N);
  9.     int right_idx=N-1;
  10.     for (int i=0; i<N; i++) scanf("%d", &A[i]);
  11.    
  12.     while (right_idx>0)
  13.     {
  14.         for (int i=0; i<=right_idx; i++)
  15.         {
  16.             if (A[i]>max)
  17.             {
  18.                 max=A[i];
  19.                 max_idx=i;
  20.             }
  21.            
  22.         }
  23.         t=A[right_idx];
  24.         A[right_idx]=max;
  25.         A[max_idx]=t;
  26.         right_idx--;
  27.         max=-1000001;
  28.         max_idx=0;
  29.     }
  30.     for (int i=0; i<N; i++) printf("%d ", A[i]);
  31.    
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement