Statistics

Problem Statement for "ChatParser"

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. ":-P;)8(Bo[B*]8^)::);^);0;OO:O):o):)"

    Returns: ":;0;OO:O)"

  2. "Hey! How are you jill? :) :) Good day"

    Returns: "Hey! How are you jill? Good day"

  3. "Cutey ;). :-) (-: :-) (-:"

    Returns: "Cutey . (-: (-:"

  4. "There are three things: 0), 1),and 2) "

    Returns: "There are three things: 0), 1),and 2) "

  5. ":) :) :) :) :) :) :) :) :) :) :) :)"

    Returns: " "

  6. ":P:):(:[:]:-P:-):-(:-[:-]:oP:o):o(:o[:o]"

    Returns: ""

  7. ""

    Returns: ""

  8. "I like talking! 8). -- wide open eyes."

    Returns: "I like talking! . -- wide open eyes."

  9. "!8P!8)!B(!B[!B]!B-P!B-!)!8-(!B-[!;-]!;oP!;o)!;o("

    Returns: "!!!!!!!B-!)!!!!!!"

  10. "::)):-:-))8)8P*)P8P8-P8^8^8^PPP:--):^^):^))::^)"

    Returns: ":):-)*)P8^8^PP:--):^^)):"

  11. "::)) ::-))"

    Returns: ":) :)"

  12. " !! How are you doing today, pogsworth? :) :) :-)"

    Returns: " !! How are you doing today, pogsworth? "

  13. "Hello how are you :) I am doing fine. :-)"

    Returns: "Hello how are you I am doing fine. "

  14. "(-: backwards smilies are not removed."

    Returns: "(-: backwards smilies are not removed."

  15. "(1)(2)(3)(4)(5)(6)(7)(8)(9)(10))8o)"

    Returns: "(1)(2)(3)(4)(5)(6)(7)((9)(10))"

  16. ":*Ph:*(i:*)s:*[ i:^Ps: ^ (a: ^ [ :^]t8Pe8)s8(t"

    Returns: "his is: ^ (a: ^ [ test"

  17. ":"

    Returns: ":"

  18. ":)):-:):)"

    Returns: "):-"

  19. ":::"

    Returns: ":::"

  20. "hi - t:)here"

    Returns: "hi - there"

  21. " : B--( :0 :o ;^ B- [8 :0) :: :O) B^p b^P :::-):- "

    Returns: " : B--( :0 :o ;^ B- [8 :0) :: :O) B^p b^P :::- "

  22. ":]"

    Returns: ""

  23. " :-):-) "

    Returns: " "

  24. "hello:"

    Returns: "hello:"

  25. ":-):*)"

    Returns: ""

  26. "::-))"

    Returns: ":)"

  27. "P"

    Returns: "P"

  28. "ENMEMMMENEMENM:)"

    Returns: "ENMEMMMENEMENM"

  29. "12345::o))67B]"

    Returns: "12345:)67"

  30. ":--)"

    Returns: ":--)"

  31. ":):)))) :8"

    Returns: "))) :8"

  32. ":-):-)"

    Returns: ""

  33. "test:;-)^(ersr:)"

    Returns: "test:^(ersr"

  34. "::))"

    Returns: ":)"

  35. ":)[:-:)[:-P):););-:)[:-P):););--);):)[:-P):););--)"

    Returns: "[:-[);-[);--)[);--)"

  36. ":)"

    Returns: ""

  37. ":O[:op"

    Returns: ":O[:op"

  38. "test:"

    Returns: "test:"

  39. "! !:()(::():P::*():^]::)):)::)::()::(] : : ) : ((:"

    Returns: "! !)(:):):)::):] : : ) : ((:"

  40. ";:))"

    Returns: ";)"

  41. "-P:"

    Returns: "-P:"

  42. " a8B d:-)e:--):(:^^Pg:)q):*) l;^n:-m):-)ab:-"

    Returns: " a8B de:--):^^Pgq) l;^n:-m)ab:-"

  43. ":-):)"

    Returns: ""

  44. "X:):)X"

    Returns: "XX"

  45. ":):):))))) :8"

    Returns: ")))) :8"

  46. "::P)"

    Returns: ":)"

  47. ":;-))blah"

    Returns: ":)blah"

  48. ":****)"

    Returns: ":****)"

  49. "HI:-("

    Returns: "HI"

  50. ":):):-) adfasdfas asdfads*P"

    Returns: " adfasdfas asdfads*P"

  51. ":-:)"

    Returns: ":-"

  52. ":-a"

    Returns: ":-a"

  53. "testing :o) oh yeah"

    Returns: "testing oh yeah"

  54. ":):):::::)-]8oPPP]"

    Returns: "::::-]PP]"

  55. "::)[ b;:-(^(P"

    Returns: ":[ b;^(P"

  56. ":********)"

    Returns: ":********)"

  57. "testme ::-"

    Returns: "testme ::-"

  58. " :- :):- :0x:* :ox(: :0) :O)x:O :q]x:-p b-P :-^)"

    Returns: " :- :- :0x:* :ox(: :0) :O)x:O :q]x:-p b-P :-^)"

  59. ":-"

    Returns: ":-"

  60. "T:*Ph:*(i:*)s:*[ :*]i:^Ps:^) :^(a:^[ :^]t8Pe8)s8(t"

    Returns: "This is a test"

  61. "this is :) a test :"

    Returns: "this is a test :"

  62. "T:*Ph:*(i:*)s:*[ :*]i:^Ps:]t8Pe8)s8(t:::-):(:;"

    Returns: "This istest:::;"

  63. ":):-)8P afgagjk agfgaja:::]]]"

    Returns: " afgagjk agfgaja::]]"

  64. "B"

    Returns: "B"

  65. "ha :^"

    Returns: "ha :^"

  66. ":);):::::)-]8oPPP]"

    Returns: "::::-]PP]"

  67. "a"

    Returns: "a"

  68. "hi:"

    Returns: "hi:"

  69. ":-hi"

    Returns: ":-hi"

  70. ":*) f())) ;] i[] ::-() :-) :) : - ) :- ) ::-)::):"

    Returns: " f())) i[] :) : - ) :- ) :::"

  71. "T:*Ph::*)s(a:^[ :^]t8Pe8)s8(t ::::))))) :8*)"

    Returns: "Th:s(a test :::)))) :"

  72. ":):)"

    Returns: ""

  73. "::)) ::-))"

    Returns: ":) :)"

    note that smilies are not removed recursively.

  74. " !! How are you doing today, pogsworth? :) :) :-)"

    Returns: " !! How are you doing today, pogsworth? "

    note that the spaces are preserved

  75. "Hello how are you :) I am doing fine. :-)"

    Returns: "Hello how are you I am doing fine. "

  76. "(-: backwards smilies are not removed."

    Returns: "(-: backwards smilies are not removed."

  77. "T:*Ph:*(i:*)s:*[ :*]i:^Ps:^) :^(a:^[ :^]t8Pe8)s8(t"

    Returns: "This is a test"

  78. ""

    Returns: ""


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: