We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4a81cde commit bc0d625Copy full SHA for bc0d625
Python_BOJ_2022/1388.py
@@ -0,0 +1,37 @@
1
+# 바닥장식
2
+n, m = map(int, input().split())
3
+graph = [list(map(str, input())) for _ in range(n)]
4
+
5
+# 수평을 체크
6
+def dfs_hori(x, y):
7
+ if 0 <= x < n and 0 <= y < m:
8
+ if graph[x][y] == "-":
9
+ graph[x][y] = "x"
10
+ dfs_hori(x, y - 1)
11
+ dfs_hori(x, y + 1)
12
+ return
13
+ else:
14
15
16
+# 수직을 체크
17
+def dfS_vert(x, y):
18
19
+ if graph[x][y] == "|":
20
21
+ dfS_vert(x - 1, y)
22
+ dfS_vert(x + 1, y)
23
24
25
26
27
+cnt = 0
28
+for i in range(n):
29
+ for j in range(m):
30
+ if graph[i][j] == "-":
31
+ dfs_hori(i, j)
32
+ cnt += 1
33
+ elif graph[i][j] == "|":
34
+ dfS_vert(i, j)
35
36
37
+print(cnt)
0 commit comments