Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- COS PRO
- DP
- BFS
- 코딩테스트
- 알고리즘
- 백준
- BOJ
- 문제풀이
- 투포인터
- db
- oracle
- MySQL
- 이분탐색
- SWEA
- 운동기록
- 시뮬레이션
- SQL
- 문제해결
- priorityqueue
- dfs
- Java
- math
- 러닝일지
- binary search
- 건강
- 문자열
- 프로그래머스
- 코테
- 자바
- greedy
Archives
- Today
- Total
슈콩
COS PRO 1급 체스의 나이트 본문




[소스 코드]
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;
}
}