提交后,第二个测试点一直显示RE,找了很多地方也没有解决,求指教!
m, n = map(int, input().split())
mp = []
temp2 = []
for i in range(m):
temp1 = input().strip()
for j in temp1:
temp2.append(j)
mp.append(temp2)
temp2 = []
direction_num = int(input())
direction = []
for i in range(direction_num):
temp = input().strip()
direction.append(temp)
#判断当前位置当前方向是否走过
vis = [[[0 for i in range(len(direction)+1)] for i in range(n)] for i in range(m)]
def dfs(x, y, t):
if t == len(direction):
mp[x][y] = '*'
return
if vis[x][y][t] == 1:
return
vis[x][y][t] = 1
if direction[t] == 'NORTH':
x = x - 1
while x >= 0 and mp[x][y] != 'X':
dfs(x, y, t+1)
x = x - 1
elif direction[t] == 'WEST':
y = y - 1
while y >= 0 and mp[x][y] != 'X':
dfs(x, y, t+1)
y = y - 1
elif direction[t] == 'EAST':
y = y + 1
while y < n and mp[x][y] != 'X':
dfs(x, y, t+1)
y = y + 1
elif direction[t] == 'SOUTH':
x = x + 1
while x < m and mp[x][y] != 'X':
dfs(x, y, t+1)
x = x + 1
x=0
y=0
for i in range(m):
for j in range(n):
if mp[i][j] == '*':
mp[i][j] = '.'
x = i
y = j
dfs(x, y, 0)
for i in range(m):
for j in range(n):
print(mp[i][j], end='')
print()