슈콩

[SWEA] 정사각형 판정 본문

Algorithms/SWEA

[SWEA] 정사각형 판정

shukong 2025. 11. 14. 18:51

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AX8BAN1qTwoDFARO

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	static char[][] map;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int n = Integer.parseInt(br.readLine());
			map = new char[n][n];
			int[] min = null;
			int[] max = null;
			for(int i=0;i<n;i++) {
				String s = br.readLine();
				for(int j=0;j<n;j++) {
					map[i][j] = s.charAt(j);
					if(map[i][j]=='#') {
						if(min==null) {
							min = new int[]{i,j};
						}
						max = new int[]{i,j};
					}
				}
			}
			String result = "no";
			if(min != null && check(min,max) && max[0]-min[0]==max[1]-min[1]) {
				result = "yes";
			}
			System.out.println("#"+tc+" "+result);
		}
	}
	private static boolean check(int[] min,int[] max) {
		for(int i=min[0];i<=max[0];i++) {
			for(int j=min[1];j<=max[1];j++) {
				if(map[i][j]!='#')
					return false;
			}
		}
		return true;
	}
}

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

[SWEA] 최장 공통 부분 수열  (0) 2025.11.14
[SWEA] 준환이의 운동관리  (0) 2025.11.14
[SWEA] 격자판 칠하기  (0) 2025.11.14
[SWEA] 식료품 가게  (0) 2025.11.14
[SWEA] 5일차 - GNS  (0) 2025.11.14