TopcoderArchive
SRM2 Jul 2007
SRM 356

SMSLanguage

Problem statement, definition, constraints, and public examples.

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"
Back to all problems