You will be fine

<Algorithm> 32. 1652번 누울 자리를 찾아라

by BFine
반응형

1. 1652번 누울 자리를 찾아라

  • 단순히 발아래에 짐이 있는지 벽이 있는지 확인하면 되는 문제, 문제를 이해하는 것이 문제

  • 2중 for문으로 가로 확인, 세로 확인 하여 풀이

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        
            int N = Integer.parseInt(br.readLine());
            int[][] arr = new int[N][N]; 
            int row = 0,col = 0;
        
            
            for(int i = 0; i < N; i++) {
                String temp = br.readLine();
                
                for(int j = 0; j < N; j++) {
                 if(temp.charAt(j) == '.') {
                    arr[i][j] = 0
                 }else {
                     arr[i][j] = 1;
                 }
               }
           }
            
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < N - 1; j++) {
                    if(arr[i][j] == && arr[i][j+1== 0) {
                            if(j+== N - 1) { // 끝이 벽인지
                                row ++;
                            }else {
                                if(arr[i][j+2== 1) {
                                    row++;  // 다음칸에 짐이 있는지
                                }
                            }
                    }
                }
            }
            
 
            for(int i = 0; i < N; i++) {
                for(int j = 0; j < N - 1; j++) {
                    if(arr[j][i] == && arr[j+1][i] == 0) {
                            if(j+== N-1) {
                                col ++;
                            }else {
                                if(arr[j+2][i] == 1) {
                                    col++;
                                }
                            }
                    }
                }
            }
            
            System.out.println(row+" "+col);
        
    }
}
cs







반응형

블로그의 정보

57개월 BackEnd

BFine

활동하기