|
|
back to boardCurrect Solution in JAVA ( 0.078 s ) 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'] ); } } } |
|
|