TopCoder problem "Foobar" used in SRM 186 (Division I Level Two)



Problem Statement

    

Some chat rooms and bulletin boards use a profanity filter to strip their user-supplied content of words that degrade the quality of discourse. This inspires a few foul-mouthed users to mask their objectionable language by replacing letters with symbols of similar shape ("shoot" may turn into "sh00t", for example), spacing out the letters ("darn" to "d a r n"), or both ("hell" to "h e 1 1", where lowercase L is replaced by the numeral 1).

You have been hired to make an intelligent filter that defeats these masking techniques. For the present purposes, the only forbidden words are "heck", "gosh", "dang", "shucks", "fooey", "snafu", and "fubar". You are given a pair of Strings, plain and code, such that the nth character of code may substitute for the nth character of plain. Take into account these potential substitutions and all possible spacings of a profane word, but disregard the characters surrounding a profane word. Given a String of text, return it in a censored form where all profanities are replaced by a sequence of asterisks in such a way that the length of the String is unaltered.

 

Definition

    
Class:Foobar
Method:censor
Parameters:String, String, String
Returns:String
Method signature:String censor(String plain, String code, String text)
(be sure your method is public)
    
 

Notes

-All characters are case-sensitive. For example, "heck" is not equivalent to "hEcK" unless the input parameters explicitly provide for it.
-Overlapping profanities should all be overwritten by asterisks, so that "dangosh", for instance, becomes "*******".
-None of the input Strings will contain control characters; text will not contain any kind of whitespace apart from the space character; neither plain nor code will contain any whitespace.
 

Constraints

-plain is between 1 and 50 characters long, inclusive
-code has the same length as plain
-text is between 1 and 50 characters long, inclusive
-each character in text has an ASCII value between 32 and 126, inclusive
-each character in plain and code has an ASCII value between 33 and 126, inclusive
 

Examples

0)
    
"ogg"
"08B"
"I say f00ey on this dan8 problem and the danB set!"
Returns: "I say ***** on this **** problem and the **** set!"
The same character may be substituted in different ways.
1)
    
"eafk"
"88$$"
"What the h 8 c $ is this s  n  8  $  u?"
Returns: "What the ******* is this *************?"
Different characters may be substituted in the same way.
2)
    
"au"
"ui"
"Dung? What the ding do you mean, dung?"
Returns: "Dung? What the ding do you mean, ****?"
Substitution is not transitive.
3)
    
"YYYggggabcdefghijklmnopqrstuvwxyz"
"XXXggggABCDEFGHIJKLMNOPQRSTUVWXYZ"
"DANGitALLtoHECK"
Returns: "****itALLto****"
Duplicate character substitutions and redundant substitutions may be specified.
4)
    
"ddhhooggss<y}T?h:1+Wd~\\\'\""
"D*HNO0G&S5Rfubar%f3k<:..."
"Dangoshucks, I say, * a n & 0 5 H u c k 5."
Returns: "***********, I say, *********************."

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=2243

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4750&pm=2243

Writer:

Eeyore

Testers:

lbackstrom , brett1479

Problem categories:

Search, String Manipulation