题目描述
Problem Description
Given a string $ S $ consisting of lowercase English letters. Perform the following operations $ 1 $ to $ N $ in ascending order on the string $ S $.
- Operation $ i $: Reverse the substring starting from the $ l_i $ -th character from the left to the $ r_i $ -th character from the left ( $1 \leq l_i < r_i \leq |S|$ ).
For example, for the string abcdef, if you reverse the substring starting from the 3rd character c to the 5th character e, you get the string abedcf.
Output the string after performing all operations from $ 1 $ to $ N $ in ascending order.
Input Format
The input is given from the standard input in the following format:
$ S $ $ N $ $ l_1 $ $ r_1 $ $ l_2 $ $ r_2 $ : $ l_N $ $ r_N $
- The first line contains a string $ S $ consisting of lowercase English letters ( $1 \leq |S| \leq 100$ ).
- The second line contains an integer $ N $ representing the number of operations ( $1 \leq N \leq 100$ ).
- The next $ N $ lines contain information about the operations. The $ i $ -th line contains two integers $ l_i $ and $ r_i $ separated by a space ( $1 \leq l_i < r_i \leq |S|$ ), indicating that operation $ i $ reverses the substring starting from the $ l_i $ -th character to the $ r_i $ -th character.
Output Format
Output the string after all operations in one line. Ensure a newline at the end of the output.
Sample Input and Output
Sample Input #1
abcdef
2
3 5
1 4
Sample Output #1
debacf
Sample Input #2
redcoat
3
1 7
1 2
3 4
Sample Output #2
atcoder
Notes/Hints
Sample Explanation 1
- After operation $ 1 $, the string becomes
abedcf. - After operation $ 2 $, the string becomes
debacf.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分
样例输入
abcdef
2
3 5
1 4
样例输出
debacf