4 / 4
Mar 2018

I am getting a wrong answer in TOANDFRO
This is my code. It works correctly on the given test cases.

import java.util.*;
public class toandfro
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t!=0){
String st = sc.next();
int rows = st.length()/t;
StringBuilder sb = new StringBuilder();
String[] strings = new String[rows];
int abc = 0;
for(int i = 0; i<st.length(); i+=t){
String sub = st.substring(i, i+t);
if(i%2!=0){
sub = new StringBuilder(sub).reverse().toString();
}
strings[abc] = sub;
abc++;
}

  	for(int j = 0; j<t; j++){
  		for(int i = 0; i<rows; i++){
  	
  			sb.append(strings[i].charAt(j));
  		}
  	}
  	
  	System.out.println(sb.toString());
  	t = sc.nextInt();
  }

}
}

  • created

    Mar '18
  • last reply

    Mar '18
  • 3

    replies

  • 936

    views

  • 2

    users

  • 1

    link

5
tdeaowsmtheooenxsrmnyaeoabftkoueeycdossneotuefrcme
8
mavsyrggemyoeeroarddfpesasteaeyndhvwnisbcancaial
0

These will both be English sentences after you’ve decoded them correctly.

The second one doesn’t make sense.

thenyouneedtomakesomemoretestcasesofyourownxabcdef
meaadcamrshavydtvnsodewcyefanarepeiigreysagosnbl

You didn’t take the hint…these will both be English sentences after you’ve decoded them correctly.