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

 

SW Expert Academy

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

swexpertacademy.com

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

char map[50][50];
int flag = 0;

void check(int y, int x) {

	int direct[4][2] = {
		0,0,
		0,1,
		1,0,
		1,1
	};

	for (int i = 0; i < 4; i++) {
		if (map[y + direct[i][0]][x + direct[i][1]] != '#') {
			flag = 1;
			return;
		}
		map[y + direct[i][0]][x + direct[i][1]] = '.';
	}
}

int main() {

	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n, m;

		for (int y = 0; y < 50; y++) {
			for (int x = 0; x < 50; x++) {
				map[y][x] = '\0';
			}
		}

		cin >> n >> m;
		
		flag = 0;
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < m; x++) {
				cin >> map[y][x];
			}
		}

		for (int y = 0; y < n; y++) {
			for (int x = 0; x < m; x++) {
				if (map[y][x] == '#') {
					check(y, x);
				}
				if (flag == 1) break;
			}
			if (flag == 1) break;
		}

		cout << "#" << i + 1 << " ";
		if (flag == 1) cout << "NO" << endl;
		else cout << "YES" << endl;
	}

	return 0;
}

+ Recent posts