Not getting correct output

You can refer the approach from here Playing with cards
Also check this code https://ide.codingblocks.com/s/259718