Fire! P73468


Statement
 

pdf   zip

thehtml

Write a program that reads a sequence of forests and prints the results of spreading all the fires of each forest.

Input

Input consists of a sequence of forest descriptions. Each description consists of a line with n and m (a pair of natural numbers strictly positive that indicate respectively the number of rows and the number of columns of the forest), followed by n lines, each one with m characters: |’A’| for a tree without fire, |’F’| for a tree with fire, and |’.’| for an empty position.

Output

For each forest of the input, print the result of spread all the fires, supposing that these are transmitted to the right, to the left, upwards and downwards, and that the final result of each fire is an empty position. Print an empty line after each forest.

Public test cases
  • Input

    3 5
    AAF.A
    .AA..
    ..A.F
    
    6 8
    A.AAA.A.
    .A...A..
    A.AAA.AF
    A.AFA.AF
    A.AAA.AF
    .A...AF.
    
    6 11
    AAA.AAAAAAA
    A.AAA......
    A.....AAA.F
    A.AAA.A.A.A
    A.A.A.A.A.A
    AAA.AAA.AAA
    

    Output

    ....A
    .....
    .....
    
    A.AAA.A.
    .A...A..
    A.......
    A.......
    A.......
    .A......
    
    ...........
    ...........
    ...........
    ...........
    ...........
    ...........
    
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Java