1. Java, Gunnar Hage

/**
* FWP-Fach: ACM programming Contest WS 08/09 "11221 Magic square palidromes"
* Verdict: accepted / 0.160
*
* Gunnar Hage, gunnarhage@gmx.de
* AP5(IFB5A) Dez. 2008
Input:
3
sator arepo tenet opera rotas
this sentence is, quite clearly, not a magic quare palindrome! but then again
muse sun, eve.s e(y)es even use sum.

Output:
Case #1:
5
Case #2:
No magic :(
Case #3:
5
*/

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

public class Main {
public static void main(String... args) throws IOException{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
for(int i=0;i<cases;i++)
{
StringBuilder sb = new StringBuilder();
String line = br.readLine();
boolean isPalindrom = false;
//filter nach kleinbuchstaben.
for(char c:line.toCharArray())
if(c>='a' && c <='z') // ist diese bedingung richtig?
sb.append(c);

double sqrt1 = Math.sqrt(sb.length());
//Abfrage, ob die zahl eine Quadratzahl ist.
if((Math.sqrt(sb.length())*1000)%1000 == 0)
{
isPalindrom = true;
int sqrt = (int)sqrt1;
for(int zl=0;zl<sqrt && isPalindrom;zl++)
for(int sp=zl;sp<sqrt-zl && isPalindrom;sp++)
{
char a = sb.charAt(sqrt*zl + sp);
isPalindrom =
(a == sb.charAt(sb.length()-1 -(sqrt*zl + sp))
&& (a == sb.charAt(sqrt*(sqrt-sp-1) + sqrt-zl-1))
&& (a == sb.charAt(sb.length()-1 -(sqrt*(sqrt-sp-1) + sqrt-zl-1))));
}
}
if(isPalindrom)
bw.append("Case #" + (i+1) + ":\n" + (int)sqrt1 + "\n");
else
bw.append("Case #" + (i+1) + ":\nNo magic :(\n");
}
bw.flush();
bw.close();
System.exit(0);
}
}