Problem:
Score : 200 points

Problem Statement

There is a grid of squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Each square is black or white.
The color of the square is given as an H-by-W matrix (a_{i, j}).
If a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.

Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:

Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.

It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#

Solution in C (GCC 9.2.1) (judge verdict: Accepted)

/* ex7-3
   Sagzar1993  */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int row, col, i, j;//行と列の数

    /*  各行・各列が全て白であるか否かを記憶する配列
        各行、各列について全てのマス目が白なら１、そうでなければ０ */
    int *ptrWhiteRow, *ptrWhiteCol;
    
    char **ptrColor; //各マスの記号の配列
    scanf("%d %d", &row, &col); //行数、列数の入力

    //各配列のポインタについて、メモリを動的確保
    ptrColor = (char**)calloc(row, sizeof(char*));
    ptrWhiteRow = (int*)calloc(row, sizeof(int));
    ptrWhiteCol = (int*)calloc(col, sizeof(int));
    //メモリの確保に失敗した場合はエラー終了
    if(ptrColor == NULL || ptrWhiteRow == NULL || ptrWhiteCol == NULL){
        exit(1);
    }
    //各行の要素分のメモリを確保
    for(i = 0; i < row; i++){
        ptrColor[i] = (char*)calloc(col, sizeof(char));
        //メモリの確保に失敗した場合はエラー終了
        if(ptrColor[i] == NULL){
            exit(1);
        }
    }

    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            scanf(" %c", &ptrColor[i][j]); //各マス目の色記号の入力
        }
    }

    for(i = 0; i < row; i++){
        for(j = 0; j < col; j++){
            if(ptrColor[i][j] != '.'){
                break; //各行について、白でないマス目があれば終了して次の行へ
            }
        }
        if(j == col){
            ptrWhiteRow[i] = 1; //行の全てのマス目が白ならwhiteRowに1を保存
        }
    }
    
    for(j = 0; j < col; j++){
        for(i = 0; i < row; i++){
            if(ptrColor[i][j] != '.'){
                break; //各列について、白でないマス目があれば終了して次の行へ
            }
        }
        if(i == row){
            ptrWhiteCol[j] = 1; //列の全てのマス目が白ならwhiteColに1を保存
        }
    }
    
    for(i = 0; i < row; i++){
        if(ptrWhiteRow[i] == 1){
            continue;  //各行について、whiteRowを参照し、その行の全てのマス目が白ならスキップ
        }

        for(j = 0; j < col; j++){
            if(ptrWhiteCol[j] == 1){
                continue; //各行の各列のマス目について、その列が全てのマス目が白である列ならスキップ
            }
            printf("%c", ptrColor[i][j]); //そのマス目の行と列がともに全て白でないときは出力
        }
        printf("\n"); //各行について、全てのマス目を調べ終えたら改行
    }
    
    //ptrColorの各行の要素分のメモリを解放
    for(i = 0; i < row; i++){
        free(ptrColor[i]);
    }
    //ptrColorの各行の配列と他の２つの配列へのポインタの領域を解放
    free(ptrColor);
    free(ptrWhiteRow);
    free(ptrWhiteCol);

    return 0;
}