Problem Statement
You are to write a decoder for a simple encryption algorithm. The encryption algorithm removes all spaces from the original string, reverses the resulting string, and finally inserts the spaces back to their original indices. For example, the string "a bc def" would be encrypted as "f ed cba". Given an encrypted string, decode it and return the original string.
Definition
- Class:
- SimpleCipher
- Method:
- decode
- Parameters:
- String
- Returns:
- String
- Method signature:
- String decode(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'), punctuation marks ('.', ',', ';', '!', '?') and spaces (' ').
Examples
"cba"
Returns: "abc"
"c b a"
Returns: "a b c"
"c ba"
Returns: "a bc"
"!dlrow ,olleH"
Returns: "Hello, world!"
Punctuation marks should also be treated as characters."bmal elt t iladah yraM"
Returns: "Mary had a little lamb"