Connection Status:
Competition Arena > ChatParser
SRM 84 · 2002-04-29 · by Echo
Class Name: ChatParser
Return Type: String
Method Name: deSmilie
Arg Types: (string)
Problem Statement

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 String, remove all the smilies from it and return the clean text. Only remove smilies in a single pass. If that single pass creates more smilies, do not remove them. For example, "::))" only contains one smilie, and the resultant text would just be ":)". (see example 0)

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).
Examples
0)
":-P;)8(Bo[B*]8^)::);^);0;OO:O):o):)"
Returns: ":;0;OO:O)"
1)
"Hey! How are you jill? :) :) Good day"
Returns: "Hey! How are you jill?   Good day"
2)
"Cutey ;).  :-) (-: :-) (-:"
Returns: "Cutey .   (-:  (-:"
3)
"There are three things: 0), 1),and 2) "
Returns: "There are three things: 0), 1),and 2) "
4)
":) :) :) :) :) :) :) :) :) :) :) :)"
Returns: "           "
72)
"::)) ::-))"
Returns: ":) :)"

note that smilies are not removed recursively.

73)
"  !! 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.

Coding Area

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

Submitting as anonymous