fork(1) download
  1. H=0...gets.to_i
  2. W=0...gets.to_i
  3. G=readlines
  4. z=->x,y{(H===y&&W===x&&' '!=G[y][x])?1:0}
  5. H.map{|j|W.map{|i|l=G[j][i]
  6. G[j][i]="@V;#{l}>Fb#{l}<Yd#{l*5}"[z[i+1,j]*8+z[i-1,j]*4+z[i,j+1]*2+z[i,j-1]]if' '!=l}}
  7. puts G
Success #stdin #stdout 0s 4760KB
stdin
7
9
  888888 
 888888  
999 98  7
 666666  
  666666 
   6666  
    6    
stdout
  d8888> 
 d8888F  
<99 98  @
 Y6666b  
  Y6666> 
   Y66F  
    V