## DWITE '11 R2 #2 - Scratch Card

View as PDF

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### 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 upper-case letters; you win by scratching letters so that they form a certain phrase, also consisting of upper-case 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 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 , the height and width of the grid. The next lines will contain upper-case letters each, describing the grid of letters. The final line of each test case will be a single string of upper-case 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

## Comments

• commented on Oct. 7, 2017, 1: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?

• commented on Oct. 7, 2017, 1: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.