Back
Close

Fencing the Cows part II

Statement

 Goal

John the farmer is back, he needs to put a fence to separate the cows living on his field.

On each side of this fence, there must be the same amount of cows in a field of size width x height.

You goal is to put the fence in the field for John the Farmer :
1) Determine the number of cows on the field
2) Display the field with the fence, a fence is represented by '|' character.

The fence is always one straight line all across the field, and always placed vertically, splitting the field into left and right.

The number of cows is always even and the locations of the cows always allow to cut the field in half, only one solution is possible for each test.
Input
Line 1: width the width of his field
Line 2: height the height of his field
Next height lines: width characters which can be '.' for grass or '#' for a cow.
Output
Line 1: totalCows the number of cows
Next height lines: width characters which can be '.' for grass, '#' for a cow or '|' for the fence
Constraints
2 ≤ totalCows ≤ 128
3 ≤ width ≤ 40
3 ≤ height ≤ 40
Example
Input
3
3
#..
..#
...
Output
2
#|.
.|#
.|.

Game modes
Fastest, Shortest, Reverse

Test cases
Test 1 Test
Input
3 3 #.. ..# ...
Output
2 #|. .|# .|.

Validator 1 Validator
Input
3 3 ..# ... #..
Output
2 .|# .|. #|.

Test 2 Test
Input
10 10 .......#.. .#........ .......... #......... ......#... .#........ ...#.....# .....#.... .......... #.......#.
Output
10 ....|..#.. .#..|..... ....|..... #...|..... ....|.#... .#..|..... ...#|....# ....|#.... ....|..... #...|...#.

Validator 2 Validator
Input
10 10 .......#.. .#........ .......... #......... .......#.. .#........ ....#....# ......#... .......... #.......#.
Output
10 .....|.#.. .#...|.... .....|.... #....|.... .....|.#.. .#...|.... ....#|...# .....|#... .....|.... #....|..#.

Test 3 Test
Input
20 5 .......#.......#.... .#...............#.. .............#.....# #................#.. .......#.........#..
Output
10 .......#......|#.... .#............|..#.. .............#|....# #.............|..#.. .......#......|..#..

Validator 3 Validator
Input
20 5 .......#......#..... .#...............#.. ............#......# #................#.. .......#.........#..
Output
10 .......#.....|#..... .#...........|...#.. ............#|.....# #............|...#.. .......#.....|...#..

Test 4 Test
Input
38 5 #.......#.####....###.#..#..####...### .#.....#..#..#...#....#..#..#.....#... ..#...#...####..##....####..###....#.. ...#.#....#..#...#....#..#..#.......#. ....#.....#..#....###.#..#..####..##..
Output
66 #.......#.####....###|#..#..####...### .#.....#..#..#...#...|#..#..#.....#... ..#...#...####..##...|####..###....#.. ...#.#....#..#...#...|#..#..#.......#. ....#.....#..#....###|#..#..####..##..

Validator 4 Validator
Input
37 5 #.......#.####...###.#..#..####...### .#.....#..#..#..#....#..#..#.....#... ..#...#...####.##....####..###....#.. ...#.#....#..#..#....#..#..#.......#. ....#.....#..#...###.#..#..####..##..
Output
66 #.......#.####...###|#..#..####...### .#.....#..#..#..#...|#..#..#.....#... ..#...#...####.##...|####..###....#.. ...#.#....#..#..#...|#..#..#.......#. ....#.....#..#...###|#..#..####..##..

Test 5 Test
Input
37 7 ##.....##.#######.##.....##.##.....## ###...###.##......##.....##.##.....## ####.####.##......##.....##.##.....## ##.###.##.#####...##.....##.######### ##.....##.##......##.....##.##.....## ##.....##.##......##.....##.##.....## ##.....##.#######..#######..##.....##
Output
128 ##.....##.#######|##.....##.##.....## ###...###.##.....|##.....##.##.....## ####.####.##.....|##.....##.##.....## ##.###.##.#####..|##.....##.######### ##.....##.##.....|##.....##.##.....## ##.....##.##.....|##.....##.##.....## ##.....##.#######|.#######..##.....##

Validator 5 Validator
Input
38 7 .##.....##.#######.##.....##.##.....## .###...###.##......##.....##.##.....## .####.####.##......##.....##.##.....## .##.###.##.#####...##.....##.######### .##.....##.##......##.....##.##.....## .##.....##.##......##.....##.##.....## .##.....##.#######..#######..##.....##
Output
128 .##.....##.#######|##.....##.##.....## .###...###.##.....|##.....##.##.....## .####.####.##.....|##.....##.##.....## .##.###.##.#####..|##.....##.######### .##.....##.##.....|##.....##.##.....## .##.....##.##.....|##.....##.##.....## .##.....##.#######|.#######..##.....##

Solution language

Solution

Stub generator input