index | submit | rank | book

index-string – String indexing

Write a program that prints the character at position n of a given string.

Input and Output

Input contains several lines. Each line of input consists of a string s followed by a number n separated by a single space. For each line of input, there should be a line of output containing the character in position n of the corresponding string s.

Each given string has at most 60 characters.

Positions on the "Hello" string

Positions are indexed from 0. If the number given on the input is 0, you should print the first character; if the number given on the input is 1, you should print the second character; if the number given on the input is 2, you should print the third character; etc.

Example Input

abcdef 0
xyz 2
Hello 1
World 4

Example Output

a
z
e
d

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 strings.

try first: fibonacci swap

try next: repeat-list

index | submit | rank | book

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