I am not able to understand how to approach this question. I did it the way I understand it but i am not getting the desired result.
Playing With Cards Query
Let’s understand the question first:
N is the no. of cards in A(0)th stack.
Q is the no. of iterations you have to perform.
Third input are N numbers, repeating the number on cards present in A(0)th stack.
You have to run a loopQ times to check for every ith prime number.
for(int i=1;i<=q;i++)
{
/*
- For each value of i, process A(i-1)th stack.
- While processing, check if the elements of A(i-1)th stack are divisible by ith prime number or not.
- if it is divisible add that element/number to B(i)th stack(B is another set of stacks).
- If not then push that element to A(i)th stack.
*/
}
Print all the stacks of B i.e. from B(0) to B(Q) and then A(Q)th stack at last.
Note: elements in stack are pushed and popped in LIFO manner.
Hope, this would help.
If you still have doubts, feel free to ask.
Can you explain this with the help of an example. I am not able to understand the sample case output.
Can you explain this with an example. I am not getting the sample test case given.
Sure,
INPUT:
N=5
Q=2
A(0)th stack : 1 2 3 4 5
Processing:
iterate for i =1 to Q;
for i=1(frst iteration):
- Pop top element of A(i-1)th (A(0)th) stack i.e. 5
- Check, ((top_element i.e. 5)%(ith prime number i.e. 1st prime number, 2)) == 0 ? Push top_element to B(i) i.e. B(1)th stack : Push top_element to A(i)i.e.A(1)th stack;
After repeating the same for all elements of stack A(0):
A(0)=[] i.e. empty as all elements have been popped.
A(1)=[5,3,1] as they are not divisible by 2.
B(1)=[4,2] as they are divisible by 2.
for i=2=Q (second and last iteration):
- Pop top element of A(i-1)th (A(1)th) stack i.e. 1
- Check, ((top_element i.e. 1)%(ith prime number i.e. 2nd prime number, 3)) == 0 ? Push top_element to B(i) i.e. B(2)th stack : Push top_element to A(i)i.e.A(2)th stack;
After repeating the same for all elements of stack A(1):
A(1)=[] i.e. empty as all elements have been popped.
A(2)=[1,5] as they are not divisible by 3.
B(2)=[3] as they are divisible by 3.
Output:
print elements of B(1),B(2),A(2)
2
4
3
5
1
Note: top element of the stack is popped first.
Hope, this would help.
Give a like if you are satisfied.
Pls have a look at the code it is showing run time error. I tried to debug it and found that uptil line 50 the code is running fine. After that the contion is not working. Code: https://ide.codingblocks.com/s/97799
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
if this much of description is given in question itself, then many of the students have not wasted their time in searching for the description.
this is the worst thing i would tell you about coding blocks. their question description and test cases are worst and not worthy.
Hey @lakshya9410,
Thanks for your feedback.
I respect your opinion but i personally feel that the amount of description they have provided for this question is enough.
You might not get an explanation like this in the online competitions you would participate.
As you are a part of CB, your opinion matters to us.
So, we will surely consider this.
Please update the description of the question. The description is same in 2021 and please give a sample test case which is easily understandable.