Problem:-

You are given a linked list that contains $N$ integers. You have performed the following reverse operation on the list:

• Select all the subparts of the list that contain only even integers. For example, if the list is $\left\{1,2,8,9,12,16\right\}$, then the selected subparts will be $\left\{2,8\right\}$$\left\{12,16\right\}$.
• Reverse the selected subpart such as $\left\{8,2\right\}$ and $\left\{16,12\right\}$.

Now, you are required to retrieve the original list.

Note: You should use the following definition of the linked list for this problem:

class Node {
Object data;
Node next;
}

Input format

• First line: $N$
• Next line: $N$ space-separated integers that denote elements of the reverse list

Output format

Print the $N$ elements of the original list.

Constraints

$1\le N\le {10}^{3}$
$1\le {A}_{i}\le {10}^{9}$

Sample Input
9
2 18 24 3 5 7 9 6 12
Sample Output
24 18 2 3 5 7 9 12 6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the sample, the original list is $\left\{24,18,2,3,5,7,9,12,6\right\}$ which when reversed according to the operations will result in the list given in the sample input.

Solution:-

#include<stdio.h>
void main()
{
int n,j,i,k;
long int a[1000],b[1000];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]%2!=0)
printf("%ld ",a[i]);
else
{
j=0;
while(1)
{
b[j]=a[i];
j++;
i++;
if(a[i]%2!=0||i==n)
break;
}
for(k=j-1;k>=0;k--)
printf("%ld ",b[k]);
i--;
}
}
}