#P2001. ACSL 2015-2016 Junior Division Contest #2 ACSL STRINGS

ACSL 2015-2016 Junior Division Contest #2 ACSL STRINGS

PROBLEM DESCRIPTION

Every computer language has different string functions and many have a different method of finding a substring. For this program you will be asked to code the algorithm that replicates the string function SUBSTR (string, start, length) as defined below:

Parameter Description
string Specifies the string on which the function is to be applied
start
  • A non-negative number – Start at a specified position in the string
  • A negative number – Start at a specified position from the end of the string
  • Note the first character on the left is in position $0$
length
  • A positive number – The number of characters to be returned from the `start` parameter
  • A negative number – The number of characters to be omitted from the end of the string
  • $0$ – Returns all the characters from the `start` parameter to the end of the string

INPUT FORMAT

There will be 66 lines of input (there are 99 shown here for extra examples). The first line will be a character string of fewer than 100100 characters. The remaining lines will each have 22 integers representing the start and length values of the function parameters.

OUTPUT FORMAT

For each set of parameter values, print the substring produced. We guarantee that the first and/or last outputted character will not be a space. We also guarantee that each substring will be valid.

SAMPLE

INPUT #1

Hello world!
0, 10
1, 8
0, 5
6, 6
0, -1
-10, -2
0, -5
-4, 0

OUTPUT #1

Hello worl
ello wor
Hello
world!
Hello world
llo worl
Hello w
rld!