Abhi is a spy. Its quite natural for him to go on a secret mission. Once You and Abhi were in the same secret mission, when Abhi felt an urgent need to communicate with Dr. Sabitabatra, who appointed both of you for this mission. The only way to communicate with him was by sending letters. As both of you were on a secret mission, Abhi will write the letter with some encrypted words which Dr. Sabitabatra was well aware of . As per the encryption is concerned, the encrypted word will start with the middle character of the string and will be formed henceforth with the middle characters of the left and right substrings (of the middle character of the word) and so on. Take a look at the explanation of the sample test case for better comprehension. As the letter was going to be quite long, Abhi wants your help to encrypt some critical words for him so that he can quickly finish the letter and sent it to Dr. Sabitabatra.
Input

2
3
abc
4
abcd

Output


bac
bacd


 Solution


import java.util.*;
class TestClass {
public static String mid(String s){
int ml=((s.length()+1)/2)-1;
if(ml>0)
return s.charAt(ml)+ mid(s.substring(0,ml))+mid(s.substring(ml+1,s.length()));
else if(ml<0)
return "";
else
return s.substring(ml);
}

public static void main(String args[] ) throws Exception {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
while(n>0)
{
int l=s.nextInt();
String str=s.next();
System.out.println(""+mid(str));
n-=1;
}
}

}





if you have any problem in this code, take a screen shot and contact with Rishabh Chaubey.
Previous Post Next Post