#C6528. Restore String Based on Indices
Restore String Based on Indices
Restore String Based on Indices
You are given a string s
and a list of indices. Your task is to reconstruct a new string where each character from s
is moved to its corresponding position as specified by the indices list. Formally, for every index \(i\) (where \(0 \leq i < n\) and \(n\) is the length of the string), the character s[i]
should be placed at position indices[i]
in the resulting string.
For example, given s = "abc"
and indices = [2, 1, 0]
, the output is "cba"
because character 'a' (position 0) moves to position 2, 'b' (position 1) moves to position 1, and 'c' (position 2) moves to position 0.
This problem tests your ability to manipulate arrays and strings while following given order constraints.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains the original string
s
. - The second line contains space-separated integers representing the
indices
where each character ins
should be placed.
outputFormat
Print the reconstructed string to stdout.
## sampleabc
2 1 0
cba