Http://ide.codingblocks.com/#/s/13611

It works fine up to third case but fails for fourth case.
I have uploaded the question. It’s question number 15.
Please rectify it.