Redaksiya
Let the array contain the numbers written on the cards. Initialize two pointers: at the beginning of the array and at its end.
To restore the original sequence, alternately take cards from the left and the right until all elements have been processed. With each selection, the corresponding pointer changes its position: moves to the right, moves to the left.
Example
Let’s consider a few steps of the algorithm using the first test case as an example.
Algorithm realization
Declare an array.
int a[100001];
Read the input data.
scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]);
Set the pointers and .
i = 0; j = n - 1;
While the inequality holds, alternately print and , simultaneously moving the pointers.
while (i <= j) { printf("%d ", a[i++]); if (i > j) break; printf("%d ", a[j--]); }