TSOC '15 Contest 2 #1 - The Code

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The students notice several sketchy papers on Mr. Venom's desk, each containing N (3 \le N \le 10\,000) integers. "A code!" Tom cries. "But how do we crack it?" replies Alex. They then see some instructions on a sticky note on one of Mr. Benum's computer monitors:

Why do they keep making me use these stupid codes?! Note to self: Start at the first integer i_1 on the paper, then skip ahead i_1 positions (or behind, if i_1 is negative). The integer you land on decodes to an uppercase alphabetic character (1 = A, 2 = B, 3 = C \ldots 26 = Z). Move to the next integer i_x after the one you just decoded and skip ahead (or behind if i_x is negative) i_x spaces from there. Repeat until you (at any point) move to a 0, at which point the program should terminate immediately. Hey, at least you will always skip to a position that's actually on the page, and there will always be a number after that. Who even designed this stupid code?

Input Specification

The first line of input consists of integer N, the number of integers on the paper. The next N lines of input contain the integers on the paper in order.

Output Specification

The output is the decoded message in uppercase.

Sample Input 1

9
2
22
5
-2
10
12
0
9
-3

Sample Output 1

EVIL

Explanation of Sample Output 1

You first skip forwards by 2 from the first integer on the page. The 5 decodes to an E. The next number after 5 is -2, so you skip 2 backwards from there, landing on the 22 which decodes to a V. The next integer is a 5, so you skip forward by 5 to 9, which decodes to I. You then skip backward by 3 from -3, landing on a 12, which decodes to L. The next number is 0, so the program terminates.

Sample Input 2

20
9
1
4
12
4
0
3
1
5
11
-10
16
5
16
-3
14
-9
5
-14
0

Sample Output 2

KIDNAPPED

Comments


  • 0
    nikos  commented on May 26, 2018, 11:24 a.m.

    I will use this code. I like it.


  • 0
    Iamhussam  commented on Sept. 7, 2017, 11:10 a.m.

    RTE ? can someone tell me why my program raises the bad_alloc error


    • 2
      Kirito  commented on Sept. 7, 2017, 11:21 a.m.

      The message terminates when it lands on a zero. There is one case where this happens that you did not consider.