Connection Status:
Competition Arena > SMSLanguage
SRM 356 · 2007-07-02 · by Pawa · String Parsing
Class Name: SMSLanguage
Return Type: String
Method Name: translate
Arg Types: (string)
Problem Statement

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.

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"
4)
"only yoyoyou"
Returns: "only yoyoU"

Submissions are judged against all 73 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SMSLanguage with a public method string translate(string text) · 73 test cases · 2 s / 256 MB per case

Submitting as anonymous