Hide

Problem C
Crazy Forks

/problems/mines18.crazyforks/file/statement/en/img-0001.png
Skokloster Castle, Erik Lernestål, cc by-sa

John runs a shop selling antique silverware. He recently got some great publicity, and now lots of people are bringing in old collections of spoons, knives, and forks. He wants to sort the forks by size, shape, and type, but there are simply too many of them. John decides to use a camera and a computer program to label the forks automatically, but he isn’t much of a programmer. John needs your crazy image-processing skills.

You helped Jon set up a camera which is reliably snapping a $50 \times 50$ black-and-white image of each fork. But John needs numerical measurements. Write some code to read in each image, and output the lengths of the handle and each of the tines.

Input

Every input is an image of some fork, drawn out with spaces (“ ”) as white pixels and hashes (“#”) as black pixels.

Each line of the input is a mix of $s$ ($0 \leq s \leq 50$) white pixels and $h$ ($1 \leq h \leq 50$) black pixels. These lines are the rows of our image.

Note: The lines may each be less than $50$ characters long, since extra spaces at the end of the line have all been removed. There may also be fewer than $50$ lines of input, since empty rows have all been removed.

Every input starts with $p$ ($1 \leq p \leq 48$) rows showing the handle of the fork. This handle section has $0$ or more white columns and then a black column.

After the end of the handle section, there is a single row of $w$ ($3 \leq w \leq 50$) black pixels, with no white pixels between them.

The remaining $r$ ($1 \leq r \leq 48$) rows show the tines of the fork. There are $t$ ($2 \leq t < w$) tines, each a column of back pixels separated by columns of white pixels. The left-most column will always be a tine. Likewise, the rightmost tine aligns with the right side of the horizontal line above.

Output

The output consists of two lines. The first line prints the length in rows, $p$, of the handle.

The second line is a space delineated list of $t$ numbers, each in the range $1 \leq x \leq r$. Each number is the length of a tine in rows, with the numbers ordered left-to-right according to the tines’ positions in the input.

Sample Input 1 Sample Output 1
  #
  #
  #
######
#  # #
#  # #
#  #
   #
3
3 4 2
Sample Input 2 Sample Output 2
       #
       #
       #
       #
##########
#  #  #  #
#  #  #
4
2 2 2 1

Please log in to submit a solution to this problem

Log in