#K69242. Reordering Strings
Reordering Strings
Reordering Strings
You are given a string s
and an array of indices. Your task is to reorder the string such that the character at the i
-th position in the original string moves to the position specified by the i
-th element of the indices array.
For example, given s = "code"
and indices [3, 1, 2, 0]
, the resulting string is "eodc". The reordering is defined by the formula:
\( \text{result}[\text{indices}[i]] = s[i] \quad \text{for} \quad 0 \leq i < |s| \)
The problem consists of processing multiple test cases. For each test case, first an input string is provided followed by a list of space-separated integers representing the new indices.
inputFormat
The first line of input contains an integer T
(number of test cases).
For each test case, there are two lines:
- The first line contains the string
s
. - The second line contains
n
space-separated integers, wheren
is the length ofs
, representing the new positions of each character ins
.
outputFormat
For each test case output the reordered string on a new line.
## sample3
code
3 1 2 0
abcd
0 1 2 3
aiohn
3 1 4 2 0
eodc
abcd
nihao
</p>