Statistics

Problem Statement for "SMSLanguage"

Problem Statement

SMS messages are short messages sent between mobile phones. The maximum length of a single message is 160 characters, so it is often necessary to abbreviate words.

You are given a String text, and your task is to translate it to SMS language according to the following rules:

  1. Remove all punctuation symbols ('.', ',', '?' and '!').
  2. Replace all uppercase letters with their lowercase equivalents.
  3. Replace all occurrences of "and" with '&'.
  4. Replace all occurrences of "ate" with '8'.
  5. Replace all occurrences of "at" with '@'.
  6. Replace all occurrences of "you" with 'U'.
All quotes are for clarity only. The rules must be applied in the order they appear in the list. For example, "I HATE rats, and you?" will be translated to "i h8 r@s & U".

Return the resulting translation as a String.

Definition

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

Constraints

  • text will contain between 1 and 50 characters, inclusive.
  • text will contain only letters ('a'-'z', 'A'-'Z'), the characters ',', '.', '!', '?', and spaces (' ').

Examples

  1. "I HATE rats, and you?"

    Returns: "i h8 r@s & U"

    The example from the problem statement.

  2. "What is the weather like today?"

    Returns: "wh@ is the we@her like today"

  3. "It is not too late to.."

    Returns: "it is not too l8 to"

  4. "this text is already in sms language"

    Returns: "this text is already in sms language"

  5. "only yoyoyou"

    Returns: "only yoyoU"

  6. "only yoyoyoU"

    Returns: "only yoyoU"

  7. "only YoYoYoU"

    Returns: "only yoyoU"

  8. ".,!?"

    Returns: ""

  9. "THIS TEXT IS ALREADY IN SMS LANGUAGE"

    Returns: "this text is already in sms language"

  10. "ate ateate ate"

    Returns: "8 88 8"

  11. "to toto to"

    Returns: "to toto to"

  12. "tototototototototototototototototototototototototo"

    Returns: "tototototototototototototototototototototototototo"

  13. "ototototototototototototototototototototototototot"

    Returns: "ototototototototototototototototototototototototot"

  14. "totoototootooototoootooootootooototoooto"

    Returns: "totoototootooototoootooootootooototoooto"

  15. "ateatateateatateateaateteateattteaaeettateatate"

    Returns: "8@88@88a8te8@tteaaeett8@8"

  16. "andatforyouyouforatandateatandforyou"

    Returns: "&@forUUfor@&8@&forU"

  17. "a,t"

    Returns: "@"

  18. "toooooooooo cooooool"

    Returns: "toooooooooo cooooool"

  19. "A..at, a t . t a "

    Returns: "a@ a t t a "

  20. " "

    Returns: " "

  21. ",.!?..??!!,......,.!?..??!!,,.!?..??!!,,.!?..??!!,"

    Returns: ""

  22. "tootoOtOotOOTooToOTOoTOO"

    Returns: "tootootootootootootootoo"

  23. "..qattaq.."

    Returns: "q@taq"

  24. "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  25. "t.......o.........o"

    Returns: "too"

  26. "A.T.E"

    Returns: "8"

  27. ".,Yo u! ! !a!!.t..A.,t.e!....and"

    Returns: "yo u @8&"

  28. "HaTe HanD YoU AteaTAte"

    Returns: "h8 h& U 8@8"

  29. "a.nd"

    Returns: "&"

  30. "a,te"

    Returns: "8"

  31. "AZ"

    Returns: "az"

  32. "a?te"

    Returns: "8"

  33. "ate"

    Returns: "8"

  34. "Y.O.U"

    Returns: "U"

  35. "at"

    Returns: "@"

  36. "a.n.d."

    Returns: "&"

  37. "a.te"

    Returns: "8"

  38. "a?nd"

    Returns: "&"

  39. " a.n.d w,h?a?t about this?? Y.O.U G.R,E,AT.ER"

    Returns: " & wh@ about this U gre8r"

  40. "an.d a,t at?e y!ou"

    Returns: "& @ 8 U"

  41. "aha?"

    Returns: "aha"

  42. " "

    Returns: " "

  43. "a,n,?!.d!"

    Returns: "&"

  44. "a"

    Returns: "a"

  45. " atAtEatatATEATE "

    Returns: " @8@@88 "

  46. "at.ea.teate"

    Returns: "888"

  47. "yoaaa"

    Returns: "yoaaa"

  48. "ate ate"

    Returns: "8 8"

  49. "ABC!!h!!!"

    Returns: "abch"

  50. "?Y.o.U!"

    Returns: "U"

  51. "yo,u are fima"

    Returns: "U are fima"

  52. "at.e"

    Returns: "8"

  53. "fate"

    Returns: "f8"

  54. " ATE uUuyou wet,we.we.tt, pwer? "

    Returns: " 8 uuuU wetwewett pwer "

  55. "atande an,d"

    Returns: "@&e &"

  56. "a,nd"

    Returns: "&"

  57. "an"

    Returns: "an"

  58. "an,d"

    Returns: "&"

  59. "...a.n.d"

    Returns: "&"

  60. "andatand.,.,atateAndyoUUUfrYOUate!!a,te"

    Returns: "&@&@8&UuufrU88"

  61. ".a.n.d."

    Returns: "&"

  62. "i am"

    Returns: "i am"

  63. "!a!n!d!"

    Returns: "&"

  64. "ha,te"

    Returns: "h8"

  65. "a a"

    Returns: "a a"

  66. "a!n!d"

    Returns: "&"

  67. " yo,u are fima "

    Returns: " U are fima "

  68. "and and you you you"

    Returns: "& & U U U"

  69. "at "

    Returns: "@ "

  70. "a?.,nd"

    Returns: "&"

  71. "a z"

    Returns: "a z"

  72. "!!!"

    Returns: ""

  73. "THIS IS A TEST CHALLENGE....!!!!"

    Returns: "this is a test challenge"


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: