#C1532. Reorder Words in Lines
Reorder Words in Lines
Reorder Words in Lines
You are given a set of lines, each containing multiple words. You are also provided with a permutation specifying the new order of words. Your task is to reorder each line according to the given permutation and output the resulting lines.
The input starts with two integers \(N\) and \(M\) where \(N\) denotes the number of lines and \(M\) indicates the number of words in each line. The next line contains \(M\) space-separated integers (0-indexed) representing the desired order of the words. Following that, there are \(N\) lines each containing \(M\) words. The output should consist of \(N\) lines with the words reordered accordingly.
inputFormat
The input is read from stdin. The first line contains two space-separated integers (N) and (M). The second line contains (M) space-separated integers representing the new order of the words (0-indexed). Each of the following (N) lines contains (M) words separated by spaces.
outputFormat
Print (N) lines to stdout. Each line must contain the words of the original line reordered according to the given indices. Words in a line should be separated by a single space.## sample
3 4
2 0 3 1
apple orange banana grape
water juice milk tea
cat dog mouse rabbit
banana apple grape orange
milk water tea juice
mouse cat rabbit dog
</p>