슈콩

COS PRO 1급 체스의 나이트 본문

카테고리 없음

COS PRO 1급 체스의 나이트

shukong 2025. 12. 9. 20:12

 

 

[소스 코드]

class Main {
    public int solution(String pos) {
        int answer = 0;
				int row = pos.charAt(1) - '0';
				int col = pos.charAt(0) - 'A' + 1;
				int[][] dirs = {
					{2,1},{1,2},
					{2,-1},{1,-2},
					{-1,2},{-2,1},
					{-2,-1},{-1,-2}
				};
				for(int[] d : dirs){
					int nr = row + d[0];
					int nc = col + d[1];
					if(nr<=0 || nr>8 || nc<=0 || nc>8) continue;
					answer++;
				}
        return answer;
    }
}