http://ideone.com/BlknGC what is the wrong with this code please explain in detail.
Check your codes output here. You have to output for “t” testcases , not for only one testcase. And the maximum string length is 50 so you have to take a character array of length 51 atleast.(you have taken length = 50).
There may be more errors or wrong logic implemented , I have not checked them .