Algorithm/SWEA

[swexpert] 1206. View

반응형

[swexpert] 1206. View


문제 출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV134DPqAA8CFAYh&categoryId=AV134DPqAA8CFAYh&categoryType=CODE


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
import java.util.Scanner;
 
public class SW문제해결_View {
 
    static int[][] arr = new int[1000][255]; // 배열 생성
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        for (int i = 1; i <= 10; i++) { // test case
            
            int cnt = 0// 조망권 수 
            int build = sc.nextInt(); // 건물 수 입력
            
            arr = new int[build][255]; // 건물 수만큼 배열 재정의
            
            for (int j = 0; j < arr.length; j++) {
                int h = sc.nextInt(); // 각 높이 입력
                for (int z = 0; z < h; z++) {
                    arr[j][z] = 1// 해당 층 value 1로 변경
                }
            }
            
            for (int j = 2; j < arr.length-2; j++) {
                for (int z = 0; z < arr[j].length; z++) {
                    if(arr[j][z] == 1) { //조망권 칸
                        if(arr[j-2][z] == 0 && arr[j-1][z] == 0 && arr[j+1][z] == 0 && arr[j+2][z] == 0) {
                            cnt++;
                        }
                    }
                }
            }
            
            System.out.println("#" + i + " " + cnt);
        }
    }
 
}
cs


반응형

'Algorithm > SWEA' 카테고리의 다른 글

[swexpert] 1210. Ladder1  (0) 2019.01.14
[swexpert] 1225. 암호생성기  (0) 2019.01.11
[swexpert] 5431. 민석이의과제체크하기  (0) 2019.01.08
[swexpert] 1208. Flatten  (0) 2019.01.08
[swexpert] 2063. 중간값 찾기  (0) 2019.01.07