#C8350. Reverse First K Elements in a Queue

    ID: 52323 Type: Default 1000ms 256MiB

Reverse First K Elements in a Queue

Reverse First K Elements in a Queue

Given a queue of integers and an integer (K), reverse the order of the first (K) elements of the queue while leaving the remaining elements in their original order. If (K) is greater than the number of elements in the queue or if (K) is non-positive, the queue should remain unchanged.

For example, if the queue is [10, 20, 30, 40, 50] and (K=3), the modified queue will be [30, 20, 10, 40, 50].

inputFormat

The input is read from standard input (stdin) and consists of two lines. The first line contains the elements of the queue separated by spaces. The second line contains a single integer (K), representing the number of elements (from the front of the queue) to reverse.

outputFormat

Output the modified queue to standard output (stdout) as a list of integers separated by spaces.## sample

10 20 30 40 50
3
30 20 10 40 50