Sorting Wooden Pieces
Time limit1sMemory limit128 MB
Simulate repeated bubble-sort passes on five labeled pieces, printing the arrangement after every swap until sorted.
- Level
Easy2 of 10
- Topics
- Simulation, Sorting, Array
- Solved
- No attempts yet
Problem
Donghyuk has five wooden pieces, each labeled with one of the numbers from 1 to 5. Every number appears on exactly one piece. He wants to arrange the pieces in the order 1 2 3 4 5 by repeatedly performing the following process.
- If the first piece has a larger number than the second piece, swap the two pieces.
- If the second piece has a larger number than the third piece, swap the two pieces.
- If the third piece has a larger number than the fourth piece, swap the two pieces.
- If the fourth piece has a larger number than the fifth piece, swap the two pieces.
- If the pieces are still not in the order
1 2 3 4 5, go back to step 1.
Given the initial order of the pieces, print the order of the pieces every time a swap is made.
Input
The first line contains the five numbers on the pieces in their current order.
Each number is between 1 and 5 inclusive, no number appears more than once, and the initial order is not 1 2 3 4 5.
Output
Whenever two pieces are swapped, print one line containing the order of the pieces after that swap.