ECOO '16 R2 P2 - CC+

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.5s
Memory limit: 64M

Problem type

CC+ is a cyclical cypher. A cyclical cypher is a method of encrypting messages in which every letter in a message is "rotated" some number of positions. For example, if the letters are rotated 1 position then a becomes b, b becomes c, and so on (z becomes a).

In a CC+ encryption (Cyclical Cypher Plus) the number of positions a given letter is rotated is based on an integer key value plus the sum of the letters to the right (where a = 0, b = 1, etc.). Messages to be encrypted by CC+ must only contain lowercase letters and space characters. No uppercase, digits, punctuation or other types of characters are allowed. Spaces in the original message are removed in the encrypted version.

Before the letters get rotated, special encoding characters are added to the left of the message string. The first two characters represent the number of words in the message as a base 26 number, using lowercase letters (a = 0, b = 1, etc.). For example, if there are 5 words, then these letters are af, which converts to 05. If there are 28 words, then the letters are bc, which converts to 12, the base-26 equivalent of the decimal number 28. This is followed by a string of characters, each of which represents the length of one of the words in the message (in the order they appeared).

Here's an example encoding using key 5:

put the lime in the coconut
Step 1:
agddecdh put the lime in the coconut
Step 2:

The input will contain 10 test cases. Each test case will consist of two lines. The first line contains an integer K (1 \le K \le 2 \times 10^9) and the second contains an encrypted or unencrypted message. Each message contains between 2 and 675 words, each from 1 to 25 characters in length. Words in unencrypted messages are separated by a single space character. Your program should either encode or decode each message (as appropriate) using key K and output the result on a single line.

Note that the sample input below consists of only two test cases, but the data files will contain 10.

Sample Input

put the lime in the coconut

Sample Output

and drink it all up

Educational Computing Organization of Ontario - statements, test data and other materials can be found at


  • 5
    marshmelllo  commented on Feb. 27, 2017, 10:12 a.m. edited

    why does the output have spaces in it?