index | submit | rank | book

index-ints – List indexing

Write a program that prints the number at position i of a given list.

Indexing integer sequences starting from 0: The number 2 is at position 3 of the sequence 16 8 4 2. The number 360 is at position 0 of the sequence 360 60 1080.

In this exercise, positions are indexed from 0. Position 0 is the first position; Position 1 is the second position; Position 2 is the third position; etc.

Input and Output

Each line of input consists of a number n, followed by n numbers, followed by number i.

For each line of input there should be a line of output with a single integer aᵢ indicating the number at position i of the input list.

The number n and thus the size of the input list will be at most 100.

Example Input

5 1 2 3 4 5 2
4 16 8 4 2 3
3 360 60 1080 0

Example Output

3
2
360

Scoring

Hints

Section 4.8. Sequences of the Computer Science by Example book discusses how to deal with sequences of values, including how to perform indexing of integer sequences.

try first: repeat-list

try next: replace

index | submit | rank | book

Copyright © 2020-2022 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/index-ints