TopcoderArchiveVisit Topcoder
SRM29 Apr 2002
SRM 84

ChatParser

Problem statement, definition, constraints, and public examples.

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)

Definition

Class:
ChatParser
Method:
deSmilie
Parameters:
String
Returns:
String
Method signature:
String deSmilie(String text)
(be sure your method is public)

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

  1. "::)) ::-))"
    Returns: ":) :)"
    note that smilies are not removed recursively.
  2. "  !! How are you doing today, pogsworth? :) :) :-)"
    Returns: "  !! How are you doing today, pogsworth?   "
    note that the spaces are preserved
  3. "Hello how are you :) I am doing fine. :-)"
    Returns: "Hello how are you  I am doing fine. "
  4. "(-: backwards smilies are not removed."
    Returns: "(-: backwards smilies are not removed."
  5. "T:*Ph:*(i:*)s:*[ :*]i:^Ps:^) :^(a:^[ :^]t8Pe8)s8(t"
    Returns: "This is a test"
  6. ""
    Returns: ""
Back to all problems