Hello
I need helo. I have runtime error (NZEC) and I dont know why.
It is problem: spoj.pl/problems/TOANDFRO/
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int PocetStlpcov = s.nextInt();
String vstup = s.next();
String[][] matica = new String[vstup.length() / PocetStlpcov][PocetStlpcov];
int index = 0;
String result = "";
int j;
String vysledok = "";
do {
// naplnenie matice
for (int i = 0; i < vstup.length() / PocetStlpcov; i++) {
if (i % 2 == 0) {
for (j = 0; j < PocetStlpcov; j++) {
matica[i][j] = "" + vstup.charAt(index);
index++;
}
} else {
for (j = PocetStlpcov - 1; j >= 0; j--) {
matica[i][j] = "" + vstup.charAt(index);
index++;
}
}
}
// Precitaj riesenie z matice
for (int i = 0; i < PocetStlpcov; i++) {
for (int k = 0; k < vstup.length() / PocetStlpcov; k++) {
result = result + matica[k][i];
}
}
vysledok = vysledok + result + '\n';
PocetStlpcov = s.nextInt();
index = 0;
result = "";
if (PocetStlpcov != 0) {
vstup = s.next();
}
} while (PocetStlpcov > 0);
System.out.println(vysledok.trim());
}
}