#C330. Reverse Substring
Reverse Substring
Reverse Substring
You are given a string s
and two integers start
and end
. Your task is to reverse the substring of s
that starts at index start
and ends at index end
(both inclusive).
In mathematical notation, if s is a string and S[i] denotes its i-th character (where indices start from 0), then the resulting string r is given by:
[ r = s[0:start] ; + ; \text{reverse}( s[start:end+1] ) ; + ; s[end+1:] ]
Assume that the input indices are valid. In case the indices are invalid, you should output an error message as described in the problem.
inputFormat
The input is read from stdin
and consists of two parts:
- The first line contains a non-empty string
s
. - The second line contains two space-separated integers,
start
andend
, indicating the start and end indices of the substring to be reversed.
You may assume that when the indices are valid, 0 \leq start \leq end < |s|
, where |s| is the length of the string.
outputFormat
The output is written to stdout
and should be the string after reversing the specified substring.
If the provided indices are invalid, output the message: "Invalid start or end indices".
## sampleabcdef
0 5
fedcba