1. JAVA, Peter Schnitzler

/* Problem 439
* Author : Peter Schnitzler
* Status : AC
* Runtim : 0.42
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {

/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
while (line != null)
{
StringTokenizer tok = new StringTokenizer(line);
String i1 = tok.nextToken();
String i2 = tok.nextToken();

int s1 = (int) i1.charAt(0) - 97;
int s2 = (int) i1.charAt(1) - 49;
int e1 = (int) i2.charAt(0) - 97;
int e2 = (int) i2.charAt(1) - 49;

int board [][] = new int[8][8];

for (int c1 = 0; c1 < 8; c1++)
{
for (int c2 = 0; c2 < 8; c2++)
{
board[c1][c2] = Integer.MAX_VALUE;
}
}

board[s1][s2] = 0;

//list of reaced squares that might have not yet reached neighbours
LinkedList<Integer> l1 = new LinkedList<Integer>();
LinkedList<Integer> l2 = new LinkedList<Integer>();

l1.add(s1);
l2.add(s2);


while(!l1.isEmpty())
{
s1 = l1.poll();
s2 = l2.poll();

int distance = board[s1][s2] + 1;

if (distance < board[e1][e2])
{
//checking all the neighbours
add(l1, l2, s1 + 1, s2 + 2, board, distance);
add(l1, l2, s1 + 1, s2 - 2, board, distance);
add(l1, l2, s1 - 1, s2 + 2, board, distance);
add(l1, l2, s1 - 1, s2 - 2, board, distance);
add(l1, l2, s1 + 2, s2 + 1, board, distance);
add(l1, l2, s1 + 2, s2 - 1, board, distance);
add(l1, l2, s1 - 2, s2 + 1, board, distance);
add(l1, l2, s1 - 2, s2 - 1, board, distance);
}

}
System.out.println("To get from " + i1 + " to " + i2 + " takes " + board[e1][e2] + " knight moves.");

//reseting the board
for (int c1 = 0; c1 < 8; c1++)
{
for (int c2 = 0; c2 < 8; c2++)
{
board[c1][c2] = Integer.MAX_VALUE;
}
}

line = reader.readLine();


}
}



private static void add(LinkedList<Integer> l1, LinkedList<Integer> l2, int z1, int z2, int board[][], int d)
{
if (z1 < 8 && z1 >= 0 && z2 < 8 && z2 >= 0)
{
if (d < board[z1][z2])
{
board[z1][z2] = d;
l1.add(z1);
l2.add(z2);
}
}
}
}