#K91332. Swap Operations on a String
Swap Operations on a String
Swap Operations on a String
You are given a string and a list of swap operations. Each swap operation is represented by a pair of indices \( (P, Q) \), where both \( P \) and \( Q \) are 0-indexed positions in the string. For each operation, swap the characters at positions \( P \) and \( Q \). If no operations are provided, the string remains unchanged.
Note: Each swap operation should be performed in the order they are given.
For example:
- For the string
abc
and swap operation(0, 2)
, the resulting string iscba
. - For the string
abcd
and swap operations(0, 1), (1, 2), (2, 3)
, the resulting string isbcda
.
inputFormat
The input is read from standard input and has the following format:
- The first line contains the initial string \( S \).
- The second line contains an integer \( N \), the number of swap operations.
- The next \( N \) lines each contain two integers \( P \) and \( Q \), representing a swap operation.
Indices are 0-indexed.
outputFormat
Output the resulting string after performing all swap operations on the initial string. The output should be written to standard output.
## sampleabc
1
0 2
cba