#P6448. Sequential Swap Sorting

    ID: 19662 Type: Default 1000ms 256MiB

Sequential Swap Sorting

Sequential Swap Sorting

Given a sequence consisting of five distinct numbers from 1 to 5, perform the following operations until the sequence becomes sorted in ascending order (i.e. \(\{1,2,3,4,5\}\)). In each full pass over the sequence, execute these steps:

  1. If \(a_1 > a_2\), swap \(a_1\) and \(a_2\) and output the current sequence.
  2. If \(a_2 > a_3\), swap \(a_2\) and \(a_3\) and output the current sequence.
  3. If \(a_3 > a_4\), swap \(a_3\) and \(a_4\) and output the current sequence.
  4. If \(a_4 > a_5\), swap \(a_4\) and \(a_5\) and output the current sequence.
  5. If the sequence is not \(\{1,2,3,4,5\}\), repeat from step 1.

Note: Output the sequence immediately after each swap. If the sequence is already sorted, no output is produced.

inputFormat

The input consists of a single line containing five integers separated by spaces. These integers form a permutation of \(1, 2, 3, 4, 5\).

outputFormat

After every swap operation, output the current sequence in a single line with each number separated by a space.

sample

5 4 3 2 1
4 5 3 2 1

4 3 5 2 1 4 3 2 5 1 4 3 2 1 5 3 4 2 1 5 3 2 4 1 5 3 2 1 4 5 2 3 1 4 5 2 1 3 4 5 1 2 3 4 5

</p>