1.

import java.io.*;
import java.util.*;


/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS11
* Problem: 11716 Digital Fortress
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2763
*
* @author Bastian Hoecker
* @author Philipp Hauck Thalheim
* @author YYY
* @version 1.0, 04/01/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.100
*/


public class DigitalFortress11716 {

/**
* @param args
*/
public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
int start = Integer.parseInt(reader.readLine());

for (int i = 0; i < start; i++) {
String s = reader.readLine();
double t = Math.sqrt(s.length());
int f = (int) t;
int count = 0;
int count2 = 0;

if (t - f == 0) {
char code[] = new char[s.length()];
for (int j = 0; j < s.length(); j++) {
if (count2 != s.length()) {
if (j + f >= s.length()) {
code[count2] = s.charAt(j);

j = count;
count++;

} else {
code[count2] = s.charAt(j);
j = j + f - 1;
}

count2++;
}
}
System.out.println(new String(code));
} else
System.out.println("INVALID");
}

}

}

2.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* Angewandte Mathematik, SS11
* Problem: 11716 Digital Fortress
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=117&page=show_problem&problem=2763
*
* @author Benedikt Z¨nnchen
* @author Erik Wenzel
* @version 1.0, 03/25/2011
*
* Method : Ad-Hoc
* Status : Accpeted
* Runtime: 0.996
*
*/

public class Main
{
public static void main(String[] args)
{
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
int rows;
try
{
rows = Integer.parseInt(sc.readLine());
String line;
int n;

while ((line = sc.readLine()) != null && rows != 0)
{
n = (int) Math.sqrt(line.length());
if (Math.pow(n,2) != (line.length()) || n == 0)
{
System.out.print("INVALID");
}
else
{
int factor = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
System.out.print(line.charAt(factor + i));
factor += n;
}
factor = 0;
}
}
System.out.println();
rows--;
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}


---------------------------------------------------------------

1.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11716 Digital Fortress
*
* @author Robert Reichart
*
* Status : Accepted
* Runtime: 0.432
*/

import java.util.*;
class Main{
public static void main(String... args){
Scanner in = new Scanner(System.in);
int cases=in.nextInt();

while(in.hasNext()){

String line = in.nextLine();
if (line.isEmpty()){continue;}

if (Math.sqrt(line.length())%1!=0){
System.out.println("INVALID");
}else{
SpecialPrintArray(CharInSQRTArray(line));
}
}
}

static char[][] CharInSQRTArray(String line){
int sqrt = (int)Math.sqrt(line.length());
char[][] letters = new char[sqrt][sqrt];
for (int i=0;i<sqrt;i++){
for (int j=0;j<sqrt;j++){
letters[i][j]=line.charAt(i*sqrt+j);
}
}
return letters;
}

static void SpecialPrintArray(char[][] letters){
StringBuilder out= new StringBuilder("");
for (int i=0;i<letters.length;i++){
for (int j=0;j<letters.length;j++){
out.append(letters[j][i]);
}
}
System.out.println(out);
}
}