Big Bang Secrets
InterviewTime limit2sMemory limit512 MB
Decode an uppercase word by shifting each letter backward by S = 3P + K positions, where P is the letter's 1-based position.
- Level
Easy2 of 10
- Topics
- Implementation, String, Math
- Solved
- No attempts yet
Problem
Sheldon and Leonard are physicists obsessed with the BIG BANG theory. To exchange secret insights, they devised a code that encrypts UPPERCASE words by shifting each letter forward.
Shifting a letter by positions means moving forward letters in the alphabet. For example, shifting B by positions gives E. Sometimes this moves past Z, the last letter of the alphabet; whenever that happens we wrap around, treating A as the letter that follows Z. For example, shifting Z by positions gives B.
The code depends on a parameter and also varies with the position of each letter in the word. For the letter at position , the shift value used is . (The first letter is at position .)
For example, here is how ZOOM is encoded when . The first letter Z has shift value ; it wraps around and becomes F. The second letter O has and becomes X. The last two letters become A and B. So Sheldon sends Leonard the secret message FXAB.
Write a program for Leonard that decodes the messages Sheldon sends.
Input
The input consists of two lines. The first line contains the positive integer (), used to compute the shift value. The second line contains the word: a sequence of uppercase letters of length at most 20.
Output
Output the decoded word of uppercase letters.