ChatParser
SRM 84 · 2002-04-29 · by Echo
Problem Statement
We want to write a chat parser that will remove all of the "smilies" from some text to make it more professional.
A "smilie" is defined as a character representing a pair of eyes, one of ':', ';', '8', or 'B', followed by an OPTIONAL nose, one of '-', 'o', '*', or '^', and finally a mouth, one of 'P', ')', '(', '[', or ']'.
For example, ":)", ";-]", "8[", "8*P", and "B^(" are all smilies, but
"X(" is not a smilie (invalid eyes)
":-" is not a smilie (no mouth)
"8v)" is not a smilie (invalid nose)
Given a
Notes
- zero, '0', and capital oh, 'O', are not valid noses; only '-', 'o' (lowercase oh), '*', and '^' are valid noses.
- all leading, trailing, and internal spaces should appear exactly in the return String as they do in the input String.
- there will be no internal spaces in a smilie. i.e., ": - )" isn't a smilie.
- do not recursively check for smilies, i.e., only do one pass. "::-))" should return ":)".
Constraints
- text is between 0 and 50 characters, inclusive.
- text will consist only of the characters 'A'-'Z', 'a'-'z', '0'-'9', spaces, and "-^:;[]().,!?*" (not including quotes).
":-P;)8(Bo[B*]8^)::);^);0;OO:O):o):)" Returns: ":;0;OO:O)"
"Hey! How are you jill? :) :) Good day" Returns: "Hey! How are you jill? Good day"
"Cutey ;). :-) (-: :-) (-:" Returns: "Cutey . (-: (-:"
"There are three things: 0), 1),and 2) " Returns: "There are three things: 0), 1),and 2) "
":) :) :) :) :) :) :) :) :) :) :) :)" Returns: " "
"::)) ::-))" Returns: ":) :)"
note that smilies are not removed recursively.
" !! How are you doing today, pogsworth? :) :) :-)" Returns: " !! How are you doing today, pogsworth? "
note that the spaces are preserved
Submissions are judged against all 78 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ChatParser with a public method string deSmilie(string text) · 78 test cases · 2 s / 256 MB per case