#P5079. Hidden Number Recognition
Hidden Number Recognition
Hidden Number Recognition
Tweetuzki wants to design a program that can recognize the hidden number in a given character matrix. The input is an \(r\times c\) matrix containing only the characters .
and #
. Some \(#\) characters form digits according to the following strict rules:
- Except for the digit 1, which occupies a \(5\times1\) rectangular area, all other digits occupy a \(5\times3\) rectangular area.
- Between any two adjacent digits (placed left to right) there is at least one column filled with
.
(i.e. digits do not touch horizontally). In other words, if two digits A and B (with A to the left of B) extend horizontally over \([l_A, r_A]\) and \([l_B, r_B]\) respectively, then \(l_B \ge r_A+2\). - The composition of the digits is fixed as follows (note: all formulas below are written in \(\LaTeX\) format):
Digit 1 (5×1): \( \begin{array}{c} # \\ # \\ # \\ # \\ # \end{array} \) For the other digits (which are 5×3), the patterns are given by: Digit 2: \( \begin{array}{ccc} # & # & # \\ . & . & # \\ # & # & # \\ # & . & . \\ # & # & # \end{array} \) Digit 3: \( \begin{array}{ccc} # & # & # \\ . & . & # \\ # & # & # \\ . & . & # \\ # & # & # \end{array} \) Digit 4: \( \begin{array}{ccc} # & . & # \\ # & . & # \\ # & # & # \\ . & . & # \\ . & . & # \end{array} \) Digit 5: \( \begin{array}{ccc} # & # & # \\ # & . & . \\ # & # & # \\ . & . & # \\ # & # & # \end{array} \) Digit 6: \( \begin{array}{ccc} # & # & # \\ # & . & . \\ # & # & # \\ # & . & # \\ # & # & # \end{array} \) Digit 7: \( \begin{array}{ccc} # & # & # \\ . & . & # \\ . & . & # \\ . & . & # \\ . & . & # \end{array} \) Digit 8: \( \begin{array}{ccc} # & # & # \\ # & . & # \\ # & # & # \\ # & . & # \\ # & # & # \end{array} \) Digit 9: \( \begin{array}{ccc} # & # & # \\ # & . & # \\ # & # & # \\ . & . & # \\ # & # & # \end{array} \) Digit 0: \( \begin{array}{ccc} # & # & # \\ # & . & # \\ # & . & # \\ # & . & # \\ # & # & # \end{array} \)Digits appear in a single horizontal row (after possible padding rows of
.
) and are separated by at least one column of.
that does not belong to any digit. Every connected block of \(#\) characters in the matrix is guaranteed to form one of the above digits.Your task is to decode the number hidden in the matrix by reading the digits from left to right and output the resulting number (with no spaces or extra characters).
## inputFormatThe input consists of multiple lines. The first line contains two integers \(r\) and \(c\) \( (1 \le r, c \le 100)\), the number of rows and columns of the matrix. The following \(r\) lines each contain a string of length \(c\), representing a row of the matrix.
## outputFormatOutput the decoded number as a continuous string of digits.
## sample5 1 # # # # #
</p>1