Advertisement
SAJID_07

Problem G

Mar 8th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,i,j,k,temp,t = 0;
  6.     cin >> n;
  7.     int a[n];
  8.     for(i = 0;i<n;i++)
  9.     {
  10.         cin >> a[i];
  11.     }
  12.     for(i = 0;i<n;i++)
  13.     {
  14.         temp = a[i];
  15.         j = i - 1;
  16.         while(j>=0 && a[j]>temp)
  17.         {
  18.             a[j+1] = a[j];
  19.             j--;
  20.         }
  21.         a[j+1] = temp;
  22.         for(k = 0;k<n;k++)
  23.         {
  24.             t = k+1;
  25.             cout << a[k];
  26.             if(t<n)
  27.                 cout << " ";
  28.         }
  29.         cout << endl;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement