软件工程今日总结

n = int(len(input()))
a = input()
b = input()
vis = [[False] * n for _ in range(2)]
def dfs(x, y):
if x < 0 or x >= 2 or y < 0 or y >= n or vis[x][y] or a[y] != '#' and b[y] != '#':
return
vis[x][y] = True
if x == 0:
if y > 0 and a[y - 1] == '#':
dfs(0, y - 1)
if y < n - 1 and a[y + 1] == '#':
dfs(0, y + 1)
if b[y] == '#':
dfs(1, y)
else:
if y > 0 and b[y - 1] == '#':
dfs(1, y - 1)
if y < n - 1 and b[y + 1] == '#':
dfs(1, y + 1)
if a[y] == '#':
dfs(0, y)
cnt = 0
for i in range(n):
if a[i] == '#' and not vis[0][i]:
dfs(0, i)
cnt += 1
if b[i] == '#' and not vis[1][i]:
dfs(1, i)
cnt += 1
print(cnt - 1 if cnt > 0 else 0)

posted @ 2025-04-21 22:49  C(5,3)  阅读(17)  评论(0)    收藏  举报