Foobar
SRM 186 · 2004-03-13 · by Eeyore
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
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
"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.
"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.
"au" "ui" "Dung? What the ding do you mean, dung?" Returns: "Dung? What the ding do you mean, ****?"
Substitution is not transitive.
"YYYggggabcdefghijklmnopqrstuvwxyz" "XXXggggABCDEFGHIJKLMNOPQRSTUVWXYZ" "DANGitALLtoHECK" Returns: "****itALLto****"
Duplicate character substitutions and redundant substitutions may be specified.
"ddhhooggss "D*HNO0G&S5Rfubar%f3k<:..." "Dangoshucks, I say, * a n & 0 5 H u c k 5." Returns: "***********, I say, *********************."
Submissions are judged against all 112 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Foobar with a public method string censor(string plain, string code, string text) · 112 test cases · 2 s / 256 MB per case