COCI 2008/2009, Contest #4
Task MJEHURIC
Goran has five wooden pieces arranged in a sequence. There is a number between 1 and 5 inscribed onevery piece, so that every number appears on exactly one of the five pieces.
Goran wants to order the pieces to form the sequence 1, 2, 3, 4, 5 and does it like this:
- If the number on the first piece is greater than the number on the second piece, swap them.
- If the number on the second piece is greater than the number on the third piece, swap them.
- If the number on the third piece is greater than the number on the fourth piece, swap them.
- If the number on the fourth piece is greater than the number on the fifth piece, swap them.
- If the pieces don't form the sequence 1, 2, 3, 4, 5, go to step 1.
Input
The first line contains five integers separated by single spaces, the ordering of the pieces.The numbers will be between 1 and 5 (inclusive) and there will be no duplicates.
The initial ordering will not be 1, 2, 3, 4, 5.
Output
After any two pieces are swapped, output the ordering of the pieces, on a single line separated by spaces.Examples
Input2 1 5 3 4 Output1 2 5 3 4 |
Input2 3 4 5 1 Output2 3 4 1 5 |
All Submissions
Best Solutions
Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Jan 19, 2009
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
Try outputting your sequence after every iteration.
Man I had to solve a+b to help you
hardest problem of my life
I print my sequence after each swap...
unless they're both wrong
1. If you want help because you're getting the answer wrong, say so. Otherwise it looks like you want help because you don't know how to solve the problem. Why can't you take an extra few seconds to be specific?
2. You seem to assume that only one of each of the steps 1-4 can be done each cycle. As a matter of fact, this is not true --- always go through these steps in order, and re-print the sequence after each swap, but do not go back to step 1 after performing a swap. Only go back to step 1 after you reach step 5.