COCI 2008/2009, Contest #4
Task MJEHURICGoran has five wooden pieces arranged in a sequence. There is a number between 1 and 5 inscribed on
every 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.
InputThe 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.
OutputAfter any two pieces are swapped, output the ordering of the pieces, on a single line separated by spaces.
2 1 5 3 4
1 2 5 3 4
2 3 4 5 1
2 3 4 1 5
Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Jan 19, 2009
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
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.