DWITE '10 R5 #1 - Colourful Words

View as PDF

Submit solution

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

Problem type
DWITE Online Computer Programming Contest, February 2011, Problem 1

Colour has often been added to words to make them seem more attractive or distinct (take the Google logo for example). However, taking a look at coloured words under coloured light makes the letters in the word that has the same colour as the light seem invisible. For example, say I have the word DWITE, and its letters are coloured blue, red, red, green and blue respectively. If you looked at the word under red light, you would only see D__TE (note the underscores, representing positions, where the W and I have been). Given coloured words and the light they are observed under, determine what you would see.

The input will contain 5 test cases. The first line of each test case consists of two words (strings with no spaces) W and C, representing the word and the colour of each letter of the word respectively (so the i^\text{th} letter of C determines the colour of the i^\text{th} letter of W, where the possible colours are b for blue, r for red, and g for green). The next line contains a string L, representing the colour of the light. L consists of either a b, r, or g (representing blue, red and green), or any combination of these letters separated by +s.

The output should consist of 5 lines, where each line contains the given word as it appears under the given light. Invisible letters are to be represented with _ underscores.

Note: There are 3 underscores after Compu in the third line of output, and the last line of output contains 5 underscores. It is also assumed that combined colours remove letters of either individual component in the combination.

Sample Input

Sample rggbbr
b
DWITE brrgb
r
Computer bbbbbrrg
r+g
February brbrbrbr
g
Sweet brgbr
r+g+b

Sample Output

Sam__e
D__TE
Compu___
February
_____

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments


  • 0
    Humanthe2nd  commented on Aug. 22, 2024, 3:25 a.m.

    If it helps anyone, I tested and found the maximum string length is 9.