Let the array contain the numbers written on the cards. Initialize two pointers: i = 0 at the beginning of the array and j = n - 1 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 i = 0 and j = n - 1.
i = 0; j = n - 1;While the inequality i \le j holds, alternately print a_i and a_j, simultaneously moving the pointers.
while (i <= j)
{
printf("%d ", a[i++]);
if (i > j) break;
printf("%d ", a[j--]);
}