Connection Status:
Competition Arena > Foobar
SRM 186 · 2004-03-13 · by Eeyore · Search, String Manipulation
Class Name: Foobar
Return Type: String
Method Name: censor
Arg Types: (string, string, string)
Problem Statement

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.

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
"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.

Coding Area

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

Submitting as anonymous