TopCoder problem "SMSLanguage" used in SRM 356 (Division II Level One)



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

0)
    
"I HATE rats, and you?"
Returns: "i h8 r@s & U"
The example from the problem statement.
1)
    
"What is the weather like today?"
Returns: "wh@ is the we@her like today"
2)
    
"It is not too late to.."
Returns: "it is not too l8 to"
3)
    
"this text is already in sms language"
Returns: "this text is already in sms language"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7929

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10765&pm=7929

Writer:

Pawa

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

String Parsing