fork(1) download
  1. def s(i):
  2. L=i.splitlines();E=enumerate;A=lambda x,y:(y,x+y,x-y);N=(2**64,)*3;X=(-2**64,)*3
  3. for y,l in E(L):
  4. for x,c in E(l):
  5. if c=='#':p=A(x,y);X=tuple(map(max,X,p));N=tuple(map(min,N,p))
  6. R=''
  7. for y,l in E(L):
  8. for x,c in E(l):
  9. if c!='.':R+=c
  10. else:p=A(x,y);f=all(N[j]<=p[j]<=X[j]for j in range(0,3));R+='.#'[f]
  11. R+='\n'
  12. return R
  13.  
  14. import sys
  15. print(s(sys.stdin.read()))
Success #stdin #stdout 0.01s 9992KB
stdin
. . . . # . . . 
 . # . . . # . .
. . . # . . . . 
 . . . . . # . .
stdout
. . # # # # . . 
 . # # # # # . .
. . # # # # # . 
 . . # # # # . .