05: Solve in C
This commit is contained in:
parent
4db64c45ca
commit
476b55d7aa
2 changed files with 574 additions and 0 deletions
511
05/input
Normal file
511
05/input
Normal file
|
@ -0,0 +1,511 @@
|
|||
[P] [C] [M]
|
||||
[D] [P] [B] [V] [S]
|
||||
[Q] [V] [R] [V] [G] [B]
|
||||
[R] [W] [G] [J] [T] [M] [V]
|
||||
[V] [Q] [Q] [F] [C] [N] [V] [W]
|
||||
[B] [Z] [Z] [H] [L] [P] [L] [J] [N]
|
||||
[H] [D] [L] [D] [W] [R] [R] [P] [C]
|
||||
[F] [L] [H] [R] [Z] [J] [J] [D] [D]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 4 from 9 to 1
|
||||
move 6 from 3 to 1
|
||||
move 7 from 4 to 1
|
||||
move 2 from 8 to 5
|
||||
move 1 from 9 to 7
|
||||
move 1 from 8 to 5
|
||||
move 3 from 6 to 4
|
||||
move 6 from 1 to 5
|
||||
move 14 from 1 to 2
|
||||
move 1 from 6 to 1
|
||||
move 2 from 6 to 2
|
||||
move 9 from 5 to 9
|
||||
move 2 from 4 to 5
|
||||
move 2 from 5 to 3
|
||||
move 6 from 9 to 6
|
||||
move 4 from 1 to 2
|
||||
move 2 from 1 to 2
|
||||
move 5 from 6 to 1
|
||||
move 1 from 4 to 9
|
||||
move 4 from 9 to 4
|
||||
move 2 from 3 to 7
|
||||
move 2 from 4 to 9
|
||||
move 2 from 9 to 6
|
||||
move 5 from 2 to 9
|
||||
move 1 from 4 to 9
|
||||
move 1 from 4 to 3
|
||||
move 5 from 9 to 8
|
||||
move 1 from 6 to 5
|
||||
move 3 from 7 to 5
|
||||
move 2 from 1 to 6
|
||||
move 5 from 6 to 8
|
||||
move 1 from 9 to 4
|
||||
move 1 from 6 to 5
|
||||
move 9 from 2 to 7
|
||||
move 1 from 2 to 3
|
||||
move 1 from 4 to 6
|
||||
move 8 from 5 to 4
|
||||
move 1 from 6 to 1
|
||||
move 2 from 8 to 6
|
||||
move 1 from 6 to 4
|
||||
move 7 from 4 to 6
|
||||
move 1 from 3 to 1
|
||||
move 1 from 3 to 4
|
||||
move 3 from 4 to 1
|
||||
move 2 from 3 to 4
|
||||
move 2 from 4 to 5
|
||||
move 3 from 5 to 7
|
||||
move 7 from 8 to 2
|
||||
move 5 from 1 to 2
|
||||
move 12 from 7 to 6
|
||||
move 2 from 1 to 9
|
||||
move 2 from 9 to 1
|
||||
move 1 from 7 to 5
|
||||
move 6 from 2 to 3
|
||||
move 5 from 2 to 6
|
||||
move 6 from 2 to 6
|
||||
move 4 from 3 to 1
|
||||
move 3 from 2 to 1
|
||||
move 1 from 5 to 4
|
||||
move 7 from 1 to 2
|
||||
move 1 from 4 to 8
|
||||
move 7 from 2 to 9
|
||||
move 5 from 2 to 8
|
||||
move 2 from 6 to 8
|
||||
move 21 from 6 to 9
|
||||
move 8 from 9 to 1
|
||||
move 2 from 6 to 1
|
||||
move 3 from 8 to 7
|
||||
move 6 from 6 to 4
|
||||
move 7 from 1 to 8
|
||||
move 1 from 9 to 1
|
||||
move 7 from 7 to 3
|
||||
move 1 from 7 to 4
|
||||
move 1 from 7 to 4
|
||||
move 7 from 8 to 1
|
||||
move 5 from 4 to 8
|
||||
move 10 from 1 to 2
|
||||
move 3 from 1 to 4
|
||||
move 3 from 2 to 9
|
||||
move 1 from 4 to 5
|
||||
move 3 from 3 to 6
|
||||
move 1 from 6 to 4
|
||||
move 1 from 6 to 7
|
||||
move 1 from 7 to 8
|
||||
move 7 from 2 to 4
|
||||
move 10 from 9 to 1
|
||||
move 10 from 4 to 5
|
||||
move 2 from 5 to 2
|
||||
move 2 from 2 to 1
|
||||
move 11 from 8 to 9
|
||||
move 7 from 1 to 4
|
||||
move 1 from 6 to 1
|
||||
move 1 from 8 to 3
|
||||
move 1 from 4 to 6
|
||||
move 6 from 4 to 5
|
||||
move 1 from 5 to 7
|
||||
move 1 from 6 to 8
|
||||
move 6 from 1 to 6
|
||||
move 19 from 9 to 2
|
||||
move 1 from 1 to 8
|
||||
move 1 from 4 to 7
|
||||
move 9 from 2 to 6
|
||||
move 1 from 9 to 2
|
||||
move 2 from 8 to 1
|
||||
move 1 from 1 to 9
|
||||
move 7 from 3 to 6
|
||||
move 3 from 9 to 2
|
||||
move 5 from 2 to 6
|
||||
move 1 from 9 to 3
|
||||
move 15 from 6 to 7
|
||||
move 6 from 6 to 7
|
||||
move 1 from 1 to 9
|
||||
move 5 from 6 to 2
|
||||
move 1 from 6 to 1
|
||||
move 6 from 5 to 8
|
||||
move 1 from 3 to 4
|
||||
move 1 from 9 to 7
|
||||
move 6 from 8 to 1
|
||||
move 3 from 4 to 6
|
||||
move 1 from 6 to 1
|
||||
move 3 from 5 to 2
|
||||
move 1 from 5 to 7
|
||||
move 5 from 1 to 5
|
||||
move 2 from 6 to 9
|
||||
move 2 from 9 to 2
|
||||
move 7 from 5 to 1
|
||||
move 1 from 5 to 7
|
||||
move 1 from 5 to 9
|
||||
move 20 from 7 to 1
|
||||
move 23 from 1 to 7
|
||||
move 1 from 1 to 2
|
||||
move 4 from 7 to 9
|
||||
move 4 from 9 to 8
|
||||
move 1 from 9 to 2
|
||||
move 16 from 7 to 6
|
||||
move 4 from 1 to 5
|
||||
move 9 from 7 to 6
|
||||
move 11 from 2 to 6
|
||||
move 1 from 1 to 9
|
||||
move 1 from 1 to 7
|
||||
move 1 from 8 to 2
|
||||
move 1 from 9 to 7
|
||||
move 4 from 5 to 2
|
||||
move 3 from 8 to 3
|
||||
move 2 from 2 to 4
|
||||
move 2 from 7 to 4
|
||||
move 4 from 4 to 9
|
||||
move 28 from 6 to 9
|
||||
move 5 from 2 to 7
|
||||
move 8 from 6 to 5
|
||||
move 6 from 2 to 6
|
||||
move 2 from 7 to 3
|
||||
move 5 from 5 to 7
|
||||
move 1 from 5 to 9
|
||||
move 14 from 9 to 4
|
||||
move 18 from 9 to 8
|
||||
move 5 from 6 to 4
|
||||
move 6 from 7 to 8
|
||||
move 1 from 2 to 6
|
||||
move 19 from 4 to 7
|
||||
move 1 from 2 to 5
|
||||
move 1 from 9 to 3
|
||||
move 2 from 5 to 2
|
||||
move 14 from 7 to 3
|
||||
move 1 from 5 to 3
|
||||
move 12 from 8 to 6
|
||||
move 6 from 6 to 5
|
||||
move 4 from 5 to 4
|
||||
move 21 from 3 to 4
|
||||
move 10 from 8 to 3
|
||||
move 2 from 3 to 2
|
||||
move 7 from 4 to 6
|
||||
move 2 from 8 to 1
|
||||
move 2 from 2 to 3
|
||||
move 5 from 7 to 2
|
||||
move 2 from 1 to 4
|
||||
move 3 from 3 to 7
|
||||
move 2 from 5 to 7
|
||||
move 2 from 2 to 7
|
||||
move 2 from 2 to 3
|
||||
move 7 from 4 to 1
|
||||
move 3 from 1 to 4
|
||||
move 3 from 2 to 5
|
||||
move 2 from 1 to 5
|
||||
move 7 from 4 to 3
|
||||
move 15 from 6 to 2
|
||||
move 1 from 1 to 4
|
||||
move 1 from 5 to 1
|
||||
move 14 from 3 to 1
|
||||
move 9 from 4 to 1
|
||||
move 5 from 7 to 1
|
||||
move 1 from 3 to 5
|
||||
move 1 from 4 to 2
|
||||
move 20 from 1 to 2
|
||||
move 17 from 2 to 5
|
||||
move 1 from 3 to 7
|
||||
move 5 from 7 to 3
|
||||
move 6 from 5 to 1
|
||||
move 3 from 3 to 2
|
||||
move 10 from 1 to 9
|
||||
move 3 from 5 to 6
|
||||
move 12 from 5 to 6
|
||||
move 1 from 5 to 1
|
||||
move 15 from 6 to 5
|
||||
move 13 from 5 to 3
|
||||
move 1 from 5 to 1
|
||||
move 10 from 3 to 2
|
||||
move 3 from 3 to 2
|
||||
move 1 from 5 to 3
|
||||
move 2 from 3 to 6
|
||||
move 1 from 3 to 4
|
||||
move 2 from 6 to 4
|
||||
move 3 from 4 to 2
|
||||
move 8 from 9 to 4
|
||||
move 8 from 4 to 8
|
||||
move 7 from 2 to 1
|
||||
move 5 from 8 to 7
|
||||
move 2 from 2 to 3
|
||||
move 13 from 1 to 2
|
||||
move 2 from 3 to 8
|
||||
move 2 from 9 to 7
|
||||
move 3 from 8 to 1
|
||||
move 2 from 1 to 2
|
||||
move 2 from 8 to 4
|
||||
move 6 from 7 to 2
|
||||
move 3 from 1 to 8
|
||||
move 1 from 7 to 5
|
||||
move 24 from 2 to 1
|
||||
move 2 from 8 to 5
|
||||
move 15 from 1 to 4
|
||||
move 1 from 5 to 8
|
||||
move 9 from 1 to 4
|
||||
move 2 from 8 to 5
|
||||
move 26 from 2 to 4
|
||||
move 1 from 5 to 8
|
||||
move 1 from 5 to 8
|
||||
move 50 from 4 to 1
|
||||
move 1 from 8 to 9
|
||||
move 1 from 4 to 6
|
||||
move 1 from 4 to 9
|
||||
move 22 from 1 to 5
|
||||
move 1 from 6 to 2
|
||||
move 1 from 5 to 8
|
||||
move 1 from 2 to 4
|
||||
move 1 from 8 to 1
|
||||
move 28 from 1 to 3
|
||||
move 2 from 9 to 4
|
||||
move 21 from 5 to 8
|
||||
move 1 from 1 to 8
|
||||
move 1 from 5 to 8
|
||||
move 1 from 5 to 7
|
||||
move 3 from 4 to 8
|
||||
move 1 from 7 to 9
|
||||
move 1 from 9 to 7
|
||||
move 20 from 8 to 4
|
||||
move 2 from 8 to 1
|
||||
move 1 from 7 to 6
|
||||
move 2 from 1 to 4
|
||||
move 27 from 3 to 1
|
||||
move 4 from 8 to 4
|
||||
move 1 from 6 to 9
|
||||
move 19 from 4 to 2
|
||||
move 5 from 2 to 5
|
||||
move 1 from 4 to 1
|
||||
move 1 from 9 to 2
|
||||
move 17 from 1 to 9
|
||||
move 1 from 3 to 8
|
||||
move 15 from 9 to 2
|
||||
move 2 from 4 to 8
|
||||
move 2 from 5 to 8
|
||||
move 2 from 5 to 9
|
||||
move 3 from 9 to 8
|
||||
move 9 from 1 to 2
|
||||
move 2 from 1 to 3
|
||||
move 4 from 4 to 5
|
||||
move 2 from 5 to 7
|
||||
move 1 from 8 to 5
|
||||
move 2 from 3 to 8
|
||||
move 4 from 5 to 2
|
||||
move 1 from 9 to 6
|
||||
move 5 from 8 to 5
|
||||
move 1 from 7 to 9
|
||||
move 29 from 2 to 3
|
||||
move 1 from 8 to 6
|
||||
move 1 from 9 to 7
|
||||
move 2 from 2 to 8
|
||||
move 2 from 5 to 2
|
||||
move 2 from 7 to 5
|
||||
move 4 from 5 to 9
|
||||
move 1 from 5 to 9
|
||||
move 10 from 3 to 4
|
||||
move 10 from 4 to 7
|
||||
move 1 from 3 to 4
|
||||
move 5 from 2 to 9
|
||||
move 5 from 8 to 6
|
||||
move 1 from 6 to 5
|
||||
move 2 from 6 to 3
|
||||
move 4 from 6 to 7
|
||||
move 1 from 5 to 2
|
||||
move 2 from 2 to 7
|
||||
move 5 from 7 to 8
|
||||
move 8 from 7 to 2
|
||||
move 6 from 8 to 7
|
||||
move 14 from 2 to 5
|
||||
move 3 from 7 to 3
|
||||
move 1 from 4 to 7
|
||||
move 2 from 7 to 2
|
||||
move 3 from 2 to 8
|
||||
move 3 from 8 to 5
|
||||
move 8 from 9 to 1
|
||||
move 3 from 7 to 2
|
||||
move 2 from 7 to 4
|
||||
move 17 from 3 to 6
|
||||
move 8 from 1 to 6
|
||||
move 16 from 5 to 2
|
||||
move 1 from 5 to 2
|
||||
move 1 from 3 to 1
|
||||
move 21 from 6 to 7
|
||||
move 1 from 4 to 8
|
||||
move 7 from 7 to 8
|
||||
move 1 from 1 to 3
|
||||
move 11 from 7 to 2
|
||||
move 7 from 2 to 6
|
||||
move 8 from 8 to 5
|
||||
move 2 from 7 to 4
|
||||
move 4 from 5 to 6
|
||||
move 8 from 2 to 8
|
||||
move 17 from 2 to 3
|
||||
move 4 from 5 to 3
|
||||
move 7 from 6 to 9
|
||||
move 2 from 6 to 9
|
||||
move 1 from 4 to 1
|
||||
move 1 from 4 to 2
|
||||
move 3 from 6 to 2
|
||||
move 1 from 6 to 8
|
||||
move 1 from 4 to 1
|
||||
move 1 from 7 to 5
|
||||
move 10 from 9 to 2
|
||||
move 1 from 5 to 6
|
||||
move 1 from 8 to 2
|
||||
move 1 from 1 to 4
|
||||
move 12 from 3 to 4
|
||||
move 1 from 6 to 2
|
||||
move 2 from 8 to 6
|
||||
move 1 from 1 to 2
|
||||
move 1 from 9 to 8
|
||||
move 2 from 8 to 7
|
||||
move 6 from 3 to 2
|
||||
move 1 from 3 to 5
|
||||
move 8 from 4 to 9
|
||||
move 22 from 2 to 9
|
||||
move 7 from 3 to 5
|
||||
move 3 from 8 to 2
|
||||
move 2 from 7 to 8
|
||||
move 3 from 6 to 9
|
||||
move 1 from 2 to 9
|
||||
move 1 from 6 to 2
|
||||
move 4 from 8 to 5
|
||||
move 5 from 5 to 9
|
||||
move 1 from 3 to 6
|
||||
move 1 from 5 to 6
|
||||
move 2 from 4 to 1
|
||||
move 2 from 2 to 4
|
||||
move 4 from 4 to 6
|
||||
move 1 from 1 to 5
|
||||
move 5 from 6 to 3
|
||||
move 35 from 9 to 1
|
||||
move 4 from 9 to 1
|
||||
move 1 from 4 to 7
|
||||
move 3 from 3 to 7
|
||||
move 37 from 1 to 7
|
||||
move 2 from 2 to 3
|
||||
move 3 from 3 to 7
|
||||
move 1 from 5 to 8
|
||||
move 2 from 1 to 8
|
||||
move 2 from 5 to 2
|
||||
move 1 from 6 to 9
|
||||
move 16 from 7 to 1
|
||||
move 5 from 1 to 5
|
||||
move 3 from 8 to 2
|
||||
move 10 from 7 to 9
|
||||
move 6 from 7 to 9
|
||||
move 3 from 2 to 1
|
||||
move 4 from 5 to 3
|
||||
move 2 from 1 to 2
|
||||
move 5 from 7 to 9
|
||||
move 5 from 7 to 9
|
||||
move 5 from 5 to 3
|
||||
move 8 from 3 to 7
|
||||
move 6 from 9 to 4
|
||||
move 8 from 7 to 3
|
||||
move 2 from 3 to 6
|
||||
move 1 from 6 to 7
|
||||
move 1 from 6 to 7
|
||||
move 5 from 4 to 9
|
||||
move 3 from 7 to 1
|
||||
move 2 from 2 to 8
|
||||
move 1 from 8 to 6
|
||||
move 6 from 1 to 8
|
||||
move 1 from 7 to 9
|
||||
move 1 from 3 to 9
|
||||
move 4 from 3 to 2
|
||||
move 8 from 1 to 6
|
||||
move 1 from 3 to 9
|
||||
move 5 from 8 to 4
|
||||
move 2 from 3 to 1
|
||||
move 1 from 8 to 2
|
||||
move 4 from 9 to 1
|
||||
move 2 from 1 to 5
|
||||
move 1 from 8 to 5
|
||||
move 11 from 9 to 5
|
||||
move 1 from 2 to 8
|
||||
move 10 from 5 to 4
|
||||
move 1 from 1 to 9
|
||||
move 3 from 5 to 4
|
||||
move 5 from 2 to 3
|
||||
move 1 from 5 to 1
|
||||
move 9 from 9 to 4
|
||||
move 1 from 6 to 7
|
||||
move 1 from 3 to 9
|
||||
move 4 from 3 to 1
|
||||
move 1 from 2 to 4
|
||||
move 1 from 1 to 4
|
||||
move 1 from 4 to 7
|
||||
move 5 from 1 to 3
|
||||
move 1 from 3 to 2
|
||||
move 1 from 8 to 3
|
||||
move 3 from 9 to 5
|
||||
move 1 from 2 to 9
|
||||
move 4 from 1 to 4
|
||||
move 1 from 7 to 4
|
||||
move 2 from 5 to 8
|
||||
move 1 from 7 to 6
|
||||
move 4 from 3 to 1
|
||||
move 1 from 5 to 8
|
||||
move 1 from 3 to 4
|
||||
move 22 from 4 to 1
|
||||
move 11 from 1 to 9
|
||||
move 2 from 1 to 4
|
||||
move 11 from 1 to 6
|
||||
move 8 from 6 to 7
|
||||
move 1 from 8 to 7
|
||||
move 7 from 9 to 2
|
||||
move 6 from 7 to 6
|
||||
move 2 from 4 to 9
|
||||
move 2 from 7 to 1
|
||||
move 14 from 6 to 3
|
||||
move 2 from 3 to 1
|
||||
move 3 from 6 to 7
|
||||
move 6 from 1 to 3
|
||||
move 8 from 9 to 6
|
||||
move 7 from 4 to 6
|
||||
move 7 from 6 to 8
|
||||
move 1 from 9 to 1
|
||||
move 2 from 9 to 8
|
||||
move 4 from 3 to 4
|
||||
move 1 from 8 to 4
|
||||
move 1 from 4 to 3
|
||||
move 6 from 3 to 7
|
||||
move 7 from 2 to 5
|
||||
move 8 from 4 to 6
|
||||
move 1 from 7 to 2
|
||||
move 1 from 5 to 7
|
||||
move 6 from 7 to 3
|
||||
move 1 from 7 to 1
|
||||
move 8 from 8 to 4
|
||||
move 8 from 4 to 2
|
||||
move 3 from 7 to 3
|
||||
move 6 from 5 to 6
|
||||
move 15 from 3 to 1
|
||||
move 21 from 6 to 1
|
||||
move 4 from 2 to 6
|
||||
move 5 from 6 to 5
|
||||
move 1 from 2 to 6
|
||||
move 1 from 4 to 5
|
||||
move 1 from 4 to 3
|
||||
move 1 from 8 to 6
|
||||
move 4 from 5 to 7
|
||||
move 18 from 1 to 4
|
||||
move 2 from 5 to 7
|
||||
move 6 from 7 to 6
|
||||
move 1 from 3 to 2
|
||||
move 6 from 1 to 2
|
||||
move 3 from 3 to 9
|
||||
move 3 from 9 to 4
|
||||
move 1 from 8 to 3
|
||||
move 1 from 6 to 5
|
||||
move 6 from 2 to 5
|
||||
move 1 from 5 to 9
|
||||
move 1 from 3 to 5
|
||||
move 2 from 6 to 8
|
||||
move 2 from 1 to 4
|
||||
move 5 from 4 to 6
|
||||
move 15 from 4 to 9
|
||||
move 5 from 9 to 1
|
||||
move 2 from 6 to 2
|
||||
move 6 from 6 to 3
|
||||
move 1 from 8 to 6
|
||||
move 6 from 5 to 9
|
||||
move 3 from 6 to 5
|
||||
move 2 from 4 to 7
|
63
05/solution.c
Normal file
63
05/solution.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
typedef struct crate {
|
||||
char c;
|
||||
struct crate *nA;
|
||||
struct crate *nB;
|
||||
} crate;
|
||||
|
||||
int main(void) {
|
||||
char l[64];
|
||||
crate *A[9] = {0}, *B[9] = {0}, *c, *p;
|
||||
int i, ll = 0, n, f, t;
|
||||
|
||||
while (fgets(l, 64, stdin)) {
|
||||
if (!ll) ll = strlen(l);
|
||||
|
||||
if (strlen(l) == ll && !isdigit(l[1])) {
|
||||
for (i = 0; i < ll / 4; i++) {
|
||||
c = calloc(1, sizeof(crate));
|
||||
c->c = l[i*4+1];
|
||||
|
||||
if (!A[i] || A[i]->c == ' ') {
|
||||
A[i] = c;
|
||||
B[i] = c;
|
||||
} else {
|
||||
for (p = A[i]; p->nA; p = p->nA);
|
||||
p->nA = c;
|
||||
for (p = B[i]; p->nB; p = p->nB);
|
||||
p->nB = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sscanf(l, "move %u from %u to %u", &n, &f, &t) == 3) {
|
||||
f--;
|
||||
t--;
|
||||
for (i = 0; i < n; i++) {
|
||||
c = A[f];
|
||||
A[f] = c->nA;
|
||||
c->nA = A[t];
|
||||
A[t] = c;
|
||||
}
|
||||
|
||||
c = B[f];
|
||||
for (i = 1; i < n; i++) c = c->nB;
|
||||
p = c->nB;
|
||||
c->nB = B[t];
|
||||
B[t] = B[f];
|
||||
B[f] = p;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Silver: ");
|
||||
for (i = 0; i < ll / 4; i++)
|
||||
if (A[i]) printf("%c", A[i]->c);
|
||||
printf("\nGold: ");
|
||||
for (i = 0; i < ll / 4; i++)
|
||||
if (B[i]) printf("%c", B[i]->c);
|
||||
printf("\n");
|
||||
}
|
Loading…
Reference in a new issue