-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_5212.py
More file actions
51 lines (42 loc) · 1.21 KB
/
Copy pathbj_5212.py
File metadata and controls
51 lines (42 loc) · 1.21 KB
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
import sys
import copy
sys.stdin = open('bj_5212_in.txt', 'r')
input = sys.stdin.readline
r, c = map(int, input().strip().split())
sea = [['.']*(c+2)]
for _ in range(r):
sea.append(list('.'+input().strip()+'.'))
sea.append(['.']*(c+2))
copy_map = copy.deepcopy(sea)
# print(copy_map)
direction = [(-1, 0), (0, 1), (+1, 0), (0, -1)]
for row in range(1, r+1): #행
for col in range(1, c+1): #열
if sea[row][col] == 'X': #육지면
cnt = 0
for dr, dc in direction: #상하좌우 확인
n_row = row + dr
n_col = col + dc
if sea[n_row][n_col] == '.': cnt += 1
if cnt >= 3:
copy_map[row][col] = '.'
else:
continue
# print(copy_map)
#직사각형 범위 찾기
up = 999
down = 0
left = 999
right = 0
for row in range(1, r+1): #행
for col in range(1, c+1): #열
if copy_map[row][col] == 'X':
up = min(up, row)
down = max(down, row)
left = min(left, col)
right = max(right, col)
# print(up, down, left, right)
for row in range(up, down+1): #행
for col in range(left, right+1): #열
print(copy_map[row][col], end='')
print()