#K33407. Ship Maneuvering Challenge
Ship Maneuvering Challenge
Ship Maneuvering Challenge
Nova is tasked with maneuvering a fleet of spaceships traveling from Earth to Mars. The ships start in a given initial order and are rearranged by a series of swap maneuvers. Each maneuver specifies two 0-indexed positions in the array of ship names, and the ships at those positions are to be swapped.
Your job is to simulate these maneuvers for each test case and output the final configuration of ships. Note that if the two indices in a maneuver are the same, no swap occurs. The input begins with an integer T indicating the number of test cases, followed by the details for each test case.
Input and output are handled via standard input and standard output.
The problem involves simulating the swaps in the order given. Make sure to process exactly N ship names for each test case.
inputFormat
The first line contains an integer T, the number of test cases.
For each test case, the input is provided in the following order:
- An integer N representing the number of ships.
- A line containing N space-separated strings, which are the names of the ships.
- An integer M representing the number of maneuvers.
- M lines, each containing two space-separated integers, a and b, representing the indices of the ships to swap (0-indexed).
outputFormat
For each test case, output a single line containing the final order of the ships as space-separated strings after all maneuvers have been performed.
## sample5
5
shipA shipB shipC shipD shipE
3
0 1
2 4
1 3
5
alpha beta gamma delta epsilon
2
0 4
2 3
4
alpha beta gamma delta
0
4
alpha beta gamma delta
1
1 1
3
x y z
2
0 1
1 2
shipB shipD shipE shipA shipC
epsilon beta delta gamma alpha
alpha beta gamma delta
alpha beta gamma delta
y z x
</p>