SquareCypher
TCO07 Round 1C · 2007-03-07 · by Mike Mirzayanov
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
Constraints
- cryptogram will contain between 1 and 50 characters, inclusive.
- cryptogram will contain only lowercase letters ('a'..'z').
"thinissacotest" Returns: "thisisacontest"
This test is from the statement.
"thisisacontest" Returns: "thisiaconstest"
"heoll" Returns: "hello"
Only the letter 'o' was moved.
"test" Returns: "test"
Obviously, short messages (not longer than 4 characters) are not change after the encryption.
"b" Returns: "b"
Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SquareCypher with a public method string decrypt(string cryptogram) · 66 test cases · 2 s / 256 MB per case