ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1197. Lonesome Knight

Currect Solution in JAVA ( 0.078 s )
Posted by Vahid Khodabakhshi 12 Nov 2009 14:00
import java.util.Scanner;
public class _1197 {
    public static void main( String[] args ) {
        int[][] chessBoard = new int[8][8];
        for( int i=0 ; i<8 ; i++ )
            for( int j=0 ; j<8 ; j++ ) {
                int counter = 0;
                if( i-2>=0 && j-1>=0 )    ++counter;
                if( i-2>=0 && j+1<=7 )    ++counter;
                if( i-1>=0 && j-2>=0 )    ++counter;
                if( i-1>=0 && j+2<=7 )    ++counter;
                if( i+2<=7 && j-1>=0 )    ++counter;
                if( i+2<=7 && j+1<=7 )    ++counter;
                if( i+1<=7 && j-2>=0 )    ++counter;
                if( i+1<=7 && j+2<=7 )    ++counter;
                chessBoard[i][j] = counter;
            }
        Scanner in = new Scanner( System.in );
        int N = in.nextInt();
        for( int i=0 ; i<N ; i++ ) {
            String p = in.next();
            System.out.println( chessBoard[p.charAt(0)-'a'][p.charAt(1)-'1'] );
        }
    }
}