Program The rantings of a lunatic Scientist

Falling Sand

C/C++ Daily Programmer

This program takes in a positive non-zero integer N representing the size of an N*N grid followed by N lines of up to N characters representing the material at each grid point.

The program then simulates the effect of gravity on grid cells marked as . (sand) causing them to fall until they land on either the floor, a stone block, or another sand block.

The simulation keeps running until the world has stabilized.

Input

5
.....
  #  
#    

    .

Output

  .
. #
#
    .
 . ..

Code