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
- SWEA
- 투포인터
- 알고리즘
- math
- 문제풀이
- dfs
- binary search
- 러닝일지
- 문자열
- COS PRO
- 문제해결
- Java
- 자바
- 운동기록
- oracle
- MySQL
- 프로그래머스
- BFS
- 코테
- 백준
- SQL
- greedy
- 이분탐색
- 시뮬레이션
- priorityqueue
- db
- BOJ
- DP
- 건강
- 코딩테스트
Archives
- Today
- Total
슈콩
COS PRO 1급 JAVA 비숍으로부터 도망쳐 본문




[소스 코드]
import java.util.*;
class Main {
int[] dx = {-1,1,-1,1};
int[] dy = {1,1,-1,-1};
public int solution(String[] bishops) {
int answer = 0;
boolean[][] visit = new boolean[8][8];
for(int i=0;i<bishops.length;i++){
int x = bishops[i].charAt(0) - 'A';
int y = bishops[i].charAt(1) - '1';
visit[x][y] = true;
for(int d=0;d<4;d++){
int nx = x + dx[d];
int ny = y + dy[d];
while(nx>=0 && nx<8 && ny>=0 && ny<8){
visit[nx][ny] = true;
nx += dx[d];
ny += dy[d];
}
}
}
for(int i=0;i<8;i++){
for(int j=0;j<8;j++){
if(!visit[i][j]) answer++;
}
}
return answer;
}
}