Xavier's assignment.

3

31 votes
Problem

Xavier is a computer science student.He is given a task by his teacher the task is to generate a code which accepts an array of n integers.He now has to select an integer from this array but there is a trick in selection of integer from the array. For the selection process he first has to accept an integer m less than the size of array,then he has to delete the mth element from this array,then again he starts counting from the next element after the deleted element in a form of loop like a circular array and deletes the m th element from that position.He continues this process until a single integer remains. Now after he has one integer remaining in that array he has to check whether it is odd or even.If that number is odd than he has to print all odd numbers present in the original array else he has to print all even numbers present in the original array. But the ouput must be in sorted manner.

INPUT:

First line contains integer n for size of array. Second line inputs the integer array. third line inputs the value of m.

OUTPUT:

The set of odd or even numbers as per the task.

CONSTRAINTS

3<n<100 1<m<n.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The first line inputs no of integer that is 6 The next line has the integer 3,5 7,1,2,8 then 3 is given as input . so,the third element is deleted now new array is 3,5,1,2,8 now begin from 1 and delete the third element from there so new array is 3,5,1,2.Now the process continues from beginning as the deleted element was the last element of array so we again begin from starting. This process is continued untill a single no. remains in the array.

Editor Image

?