알고리즘/SWEA D2 1979. 어디에 단어가 들어갈 수 있을까 - https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PuPq6AaQDFAUq SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! www.swexpertacademy.com import java.util.Scanner; public class Solution { static int T, N, W; static int [][] map; public static void main(String[] args) { Scanner scanner = new Scanner(src); T = scanner.nextInt(); for(int t=1; t<=T; t++) { int answer = 0; N = scanner.nextInt(); map = new int[N][N]; W = scanner.nextInt(); for(int row=0; row<N; row++) { for(int col=0; col<N; col++) { map[row][col]=scanner.nextInt(); } } // 입력 완료------------------------------------------- for(int row=0; row<N; row++) { for(int col=0; col<N; col++) { if(isStartCol(row, col)) { if(getColLen(row, col)==W) { answer++; } } if(isStartRow(row, col)) { if(getRowLen(row, col)==W) { answer++; } } } } // 처리 완료------------------------------------------- System.out.printf("#%d %d%n",t, answer); } } static boolean isStartRow(int row, int col) { return row==0 || map[row-1][col]==0; } static boolean isStartCol(int row, int col) { return col==0 || map[row][col-1]==0; } static int getRowLen(int row, int col) { int len = 0; for(int r=row; r<N; r++) { if(map[r][col]==1) { len++; }else { break; } } return len; } static int getColLen(int row, int col) { int len = 0; for(int c=col; c<N; c++) { if(map[row][c]==1) { len++; }else { break; } } return len; } static String src = "4\r\n" + "2 2 2\r\n" + "3 4\r\n" + "2 2 2\r\n" + "1 2\r\n" + "2 2 1\r\n" + "4 2\r\n" + "2 2 1\r\n" + "3 2"; } 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기모두의 코딩 저작자표시 비영리 변경금지 Contents 당신이 좋아할만한 콘텐츠 D3 1860. 진기의 최고급 붕어빵 2019.07.26 D3 1860. 진기의 최고급 붕어빵 2019.07.26 D3 7675. 통역사 성경이 2019.07.24 D3 3431. 준환이의 운동관리 2019.07.23 댓글 0 + 이전 댓글 더보기