TopcoderArchive
Archive
Algorithm problem

SimpleCipher

Problem statement, definition, constraints, and public examples.

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

  1. "cba"
    Returns: "abc"
  2. "c b a"
    Returns: "a b c"
  3. "c ba"
    Returns: "a bc"
  4. "!dlrow ,olleH"
    Returns: "Hello, world!"
    Punctuation marks should also be treated as characters.
  5. "bmal elt t iladah yraM"
    Returns: "Mary had a little lamb"
Back to all problems