SMS
SRM 251 · 2005-07-12 · by dimkadimon
Problem Statement
Short message service (SMS) has become a fast and quick method for communication. Most service providers place a restriction on the size of messages and hence it is important to write concise messages. Mobile phone users have found methods for compressing their messages such that the content of the messages remains unaltered. One such method is to take the original message and remove all interior vowels from each word. A vowel is interior if there is at least one consonant to the left and right (not necessarily adjacent) of the vowel in the same word.
Given a
Notes
- Vowels are 'a', 'e', 'i', 'o' and 'u' (in both upper and lower cases).
Constraints
- originalMessage will contain between 0 and 50 characters inclusive.
- originalMessage will contain only letters ('a'-'z', 'A'-'Z') and spaces.
"Lets meet tomorrow" Returns: "Lts mt tmrrw"
"Lets" becomes "Lts". "meet" becomes "mt". "tomorrow" becomes "tmrrw".
"Please come to my party" Returns: "Plse cme to my prty"
Note that vowels on the end of words are not compressed.
" I like your style " Returns: " I lke yr style "
Note that 'y' is always considered a consonant in this problem.
"Where are you" Returns: "Whre are you"
"short message service" Returns: "shrt mssge srvce"
" " Returns: " "
all spaces
"ZaaaaaaaAaAAaaAAAaaaAAAaaaaaaaaAaAaAAaaAaaaAAaaAaZ" Returns: "ZZ"
48 a's. Lots of compression.
"aaaaaaaaAaAAaaAAAaaaAAAaaaaaaaaAaAaAAaaAaaaAAaaAaa" Returns: "aaaaaaaaAaAAaaAAAaaaAAAaaaaaaaaAaAaAAaaAaaaAAaaAaa"
no consonants -> no compression
Submissions are judged against all 106 archived test cases, of which 8 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SMS with a public method string compress(string originalMessage) · 106 test cases · 2 s / 256 MB per case