DWITE '11 R2 #2 - Scratch Card

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 64M

Problem type
DWITE, November 2011, Problem 2

The economically questionable lottery business is making a mass-produced rectangular scratch card. It consists of a grid of hidden uppercase letters; you win by scratching letters so that they form a certain phrase, also consisting of uppercase letters. It might look like this one, where you would like to find the phrase DWITEISAWESOMEHAHA:

DLFKJW
FKIGDT
EKIKSA
WQEDSO
MEHAHA

You would like to mass produce correctly scratched scratch cards, to sell in the black market. To do this, you would like to have a stencil, of the same size as the grid. For example, using this stencil, where . means "scratch" and # means "don't scratch":

.####.
##.##.
.#.#..
.#.#..
......

You obtain the correct solution:

D####W
##I##T
E#I#SA
W#E#SO
MEHAHA

Given a grid of letters and a phrase, you would like to construct a stencil to solve this puzzle. If, in fact, there is no solution, you should output a stencil with the letter x for each spot.

The input will contain 5 test cases. Each test case will begin with a line of two space-separated integers 1 \le H, W \le 10, the height and width of the grid. The next H lines will contain W uppercase letters each, describing the grid of letters. The final line of each test case will be a single string of uppercase letters, the solution string.

The output will contain 5 sets of stencils, as described above. You may assume that solutions are unique. Refer to the sample examples for the output format.

Sample Input

5 6
DLFKJW
FKIGDT
EKIKSA
WQEDSO
MEHAHA
DWITEISAWESOMEHAHA
2 2
AB
CD
E

Sample Output

.####.
##.##.
.#.#..
.#.#..
......
xx
xx

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments


  • 0
    max  commented on Oct. 7, 2017, 5:05 a.m.

    If your code has two occurrences of a letter to choose from, should it always choose to "scratch" out the first occurrence of the letter?


    • 1
      Phoenix1369  commented on Oct. 7, 2017, 5:26 p.m. edited

      You may assume that solutions are unique.

      Edit: Think about what your variable message holds after the execution of your for loop.