Rolling Encryption

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 64M

Problem type

You have a sequence of lowercase characters that you want to encrypt.

The first k characters will be encoded as plain-text. All characters after the first k characters will be shifted by the most frequently occurring character that appeared in the previous k characters, with ties broken by the character which occurs first in the alphabet.

By "shifted by", we mean that if c was the most frequently occurring character, the character would be shifted ahead by 3 positions (since c is the third letter of the alphabet), modulo 26 (e.g., b becomes e, and z becomes c).

Input Specification

The first line of input contains k (1 \le k \le 10\,000). The next line contains c characters (1 \le c \le 100\,000).

Output Specification

One line, containing the encrypted version of the c characters from the input.

Sample Input

5
abbaabbacdecde

Output for Sample Input

abbaacdcdegdgh

Troy Vasiga

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments


  • -1
    SKTSnaker  commented on Feb. 26, 2017, 10:07 p.m.

    I think the sample output may be incorrect.

    Take the third last character (c) and the previous 5 characters(bacde) The shift with b should be 2 instead of 1.

    Therefore shouldn't d be e?


    • 0
      Phoenix1369  commented on Feb. 26, 2017, 10:33 p.m.

      ties broken by the character which occurs first in the alphabet.


  • 2
    bobhob314  commented on June 26, 2015, 2:27 p.m. edit 7

    Helpful Notice

    By

    the previous k characters,

    Mr. Vasiga means in the original, unaltered string.