Problem Statement
PROBLEM STATEMENT You're building a "clean" chat room, so you want to be able to filter out certain words. Given a "proposed" text message that a user has typed and a list of banned words, return a filtered version of the message in which any banned words have been replaced by asterisks (*). DEFINITION Class: CleanChat Method name: filterWords Parameters: String, String[] Return type: String Method signature: String filterWords(String message, String[] banned); (be sure your method is public) NOTES - Each banned word is replaced by a series of asterisks, one asterisk for each letter in the word. - Banned words should be recognized in a case-insensitive way. - Banned words will be blocked even if they appear within a longer word (see examples). - Banned words may overlap. Letters may therefore be replaced by asterisks multiple times, but the result will be the same as if they were replaced once (see examples). TopCoder will ensure that: * The message may contain only upper and lower case letters [A-Z,a-z], digits [0-9] (inclusive), and some punctuation: period, exclamation mark, comma, question mark, semicolon, colon, and parentheses: .!,?;:() * The message will be 0 to 50 characters in length, inclusive. * Each banned word will be 1 to 20 characters in length, inclusive. * Each banned word will contain only lower case letters [a-z], no punctuation, numbers or spaces. * There will be 0 to 50 banned words, inclusive. EXAMPLES (Quotes are for clarity only.) message = "Testing the filter." banned = ["test","sting","he"] First, the Test in Testing is filtered out. Next, "sting" is replaced; even though the "st" was already replaced in the first step, "sting" still must be recognized and replaced because it appeared in the original string. Finally, "he" is filtered out, and the end result is: Return value: "******* t** filter." message = "Thou testest the filter." banned = ["test"] Return value: "Thou ******* the filter." message = "Testing with no filter." banned = [] Return value: "Testing with no filter." message = "No,words split by punctuation are not blocked." banned = ["now"] Return value: "No,words split by punctuation are not blocked." message = "Nor are words split by a space." banned = ["rare"] Return value: "Nor are words split by a space." message = "Punctuation? Why, yes; there is! (Of course. :)" banned = ["on","y","is","ours","of"] Return value: "Punctuati**? Wh*, *es; there **! (** c****e. :)" message = "" banned = ["empty","message"] Return value: ""
Definition
- Class:
- CleanChat
- Method:
- filterWords
- Parameters:
- String, String[]
- Returns:
- String
- Method signature:
- String filterWords(String param0, String[] param1)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.