#C2924. Reverse Substring
Reverse Substring
Reverse Substring
In this problem, you are given a string ( s ) and two integers, ( start ) and ( end ). Your task is to reverse the substring of ( s ) starting at index ( start ) and ending at index ( end ) (both inclusive), while leaving the rest of the string unchanged.
Important considerations:
- If either index lies out of bounds, they should be clamped to the valid range \([0, |s|-1]\), where \(|s|\) is the length of the string.
- If \( start > end \), swap the values so that the substring boundaries are correct.
For example, if ( s = \texttt{"hello world"} ), ( start = 0 ) and ( end = 4 ), then after reversing the substring ( \texttt{"hello"} ), the final string becomes ( \texttt{"olleh world"} ).
inputFormat
Input is read from standard input (stdin). The first line contains the string ( s ). The second line contains the integer ( start ), and the third line contains the integer ( end ).
outputFormat
Output the modified string after reversing the substring from index ( start ) to ( end ) (inclusive). The output should be printed to standard output (stdout).## sample
hello world
0
4
olleh world