TopcoderArchive
TCO7 Mar 2007
TCO07 Round 1C

SquareCypher

Problem statement, definition, constraints, and public examples.

Problem Statement

Square cypher is very simple and easy to decrypt. It encrypts a message s=s0s1...sn-1 in the following way: all characters situated on square positions (0, 1, 4, 9, 16...) are moved to the front of the message. The relative order of the moved characters remains the same. For example, the message "thisisacontest" will be encrypted as "thinissacotest".

You are given a String cryptogram. Decrypt it and return the result.

Definition

Class:
SquareCypher
Method:
decrypt
Parameters:
String
Returns:
String
Method signature:
String decrypt(String cryptogram)
(be sure your method is public)

Constraints

  • cryptogram will contain between 1 and 50 characters, inclusive.
  • cryptogram will contain only lowercase letters ('a'..'z').

Examples

  1. "thinissacotest"
    Returns: "thisisacontest"
    This test is from the statement.
  2. "thisisacontest"
    Returns: "thisiaconstest"
  3. "heoll"
    Returns: "hello"
    Only the letter 'o' was moved.
  4. "test"
    Returns: "test"
    Obviously, short messages (not longer than 4 characters) are not change after the encryption.
Back to all problems