https://level.goorm.io/exam/195689/%EA%B5%AC%EB%A6%84-%EC%B0%BE%EA%B8%B0-%EA%B9%83%EB%B0%9C/quiz/1
import java.util.*;
class Main {
static int[][] cloud;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
cloud = new int[N+2][N+2];
// 구름판 채우기
for(int i=1; i<N+1; i++){
for(int j=1; j<N+1; j++){
cloud[i][j]=sc.nextInt();
}
}
// 깃발 개수 구하기
int[][] flag = new int[N+2][N+2];
for(int i=1; i<N+1; i++){
for(int j=1; j<N+1; j++){
flag[i][j]=checkCloud(i,j);
}
}
// 주어진 깃발 개수랑 같은 칸 수 세기
int result=0;
for(int i=1;i<N+1;i++){
for(int j=1;j<N+1;j++){
if(cloud[i][j]!=1 && flag[i][j]==K){
result++;
}
}
}
System.out.println(result);
}
static int[] x = {-1,0,1,-1,1,-1,0,1};
static int[] y = {-1,-1,-1,0,0,1,1,1};
public static int checkCloud(int i,int j){
int count =0;
for(int k=0;k<8;k++){
if(cloud[i+x[k]][j+y[k]]==1){
count++;
}
}
return count;
}
}
분명 비슷한 문제 풀었었는데 어떻게 풀었는지 기억이 나지 않는다.
'JAVA' 카테고리의 다른 글
구름톤 챌린지 9일차 (0) | 2023.08.25 |
---|---|
구름톤 챌린지 8일차 (0) | 2023.08.23 |
구름톤 챌린지 2일차 (0) | 2023.08.15 |
구름톤 챌린지 1일차 (0) | 2023.08.14 |
[리트코드/자바] 1732.find the highest altitude (0) | 2023.07.20 |
댓글