COCI '08 Contest 4 #1 Mjehuric

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Goran 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:

  1. If the number on the first piece is greater than the number on the second piece, swap them.
  2. If the number on the second piece is greater than the number on the third piece, swap them.
  3. If the number on the third piece is greater than the number on the fourth piece, swap them.
  4. If the number on the fourth piece is greater than the number on the fifth piece, swap them.
  5. If the pieces don't form the sequence 1, 2, 3, 4, 5, go to step 1.

Write a program that, given the initial ordering of the pieces, outputs the ordering after each swap.

Input Specification

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 Specification

After any two pieces are swapped, output the ordering of the pieces, on a single line separated by spaces.

Sample Input 1

2 1 5 3 4

Sample Output 1

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

Sample Input 2

2 3 4 5 1

Sample Output 2

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

Comments


  • 0
    lHarryl372  commented on Sept. 2, 2020, 6:22 p.m.

    I would literally give up if the amount of numbers isn't 5, but again this is only a 3-pointer, so pretty reasonable.


  • 1
    Jonathan_Uy  commented on June 9, 2020, 9:17 a.m.

    The output for Sample Input 2 is labelled as Sample Output 1


    • 1
      Pookmeister  commented on June 9, 2020, 10:58 a.m.

      Fixed, thanks!