Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import sys
  2. N = int(sys.stdin.readline())
  3. M = int(sys.stdin.readline())
  4. Map = [["."] * (M + 2)]
  5. for i in range(N):
  6.    Map.append(list("." + sys.stdin.readline().rstrip() + '.'))
  7. Map.append(['.'] * (M + 2))
  8. for y in range(1, N + 1):  
  9.   for x in range(1, M + 1):    
  10.     if Map[y][x] == '.' and (      Map[y - 1][x] == '#' or Map[y + 1][x] == '#' or      Map[y][x - 1] == '#' or Map[y][x + 1] == '#' or      Map[y - 1][x - 1] == '#' or Map[y - 1][x + 1] == '#' or      Map[y + 1][x - 1] == '#' or Map[y + 1][x + 1] == '#'):      
  11.       Map[y][x] = '*'      
  12.       cx = x        
  13.       cy = y
  14. while True:  
  15.         sys.stdout.write(str(cy) + ' ' + str(cx) + '\n')  
  16.         Map[cy][cx] = '.'  
  17.         for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):    
  18.           if Map[cy + dy][cx + dx] == '*':      
  19.             cx += dx      
  20.             cy += dy    
  21.             break  
  22.         else:    
  23.             break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement