/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
高さ H ピクセル、幅 W ピクセルの白黒画像があります。
上から i 行目、左から j 列目のピクセルの色は文字 C_{i,j} として与えられ、. は白、# は黒を表します。
この画像の上下左右の端から、すべてのピクセルが白であるような行や列を削除します。 具体的には、次の処理を順に行います。
- 画像の最上行がすべて白である限り、最上行を削除することを繰り返す。
- 画像の最下行がすべて白である限り、最下行を削除することを繰り返す。
- 画像の最左列がすべて白である限り、最左列を削除することを繰り返す。
- 画像の最右列がすべて白である限り、最右列を削除することを繰り返す。
処理後の画像を出力してください。
なお、与えられる画像には黒いピクセルが少なくとも 1 つ存在します。
制約
- 1 \le H, W \le 50
- C_{i,j} は
.または#である - 黒いピクセルが少なくとも 1 つ存在する
入力
入力は以下の形式で標準入力から与えられる。
H W
C_{1,1}C_{1,2}\ldots C_{1,W}
C_{2,1}C_{2,2}\ldots C_{2,W}
\vdots
C_{H,1}C_{H,2}\ldots C_{H,W}
出力
処理後の画像を、以下の形式で出力せよ。
ここで、h,w は処理後の画像の高さと幅(ピクセル単位)である。
また、c_{i,j} は処理後の画像の上から i 行目、左から j 列目のピクセルの色を表す文字であり、白のときは . 、黒のときは # とする。
c_{1,1}c_{1,2}\ldots c_{1,w}
c_{2,1}c_{2,2}\ldots c_{2,w}
\vdots
c_{h,1}c_{h,2}\ldots c_{h,w}
入力例 1
4 5 ..... ..#.. .###. .....
出力例 1
.#. ###
上端の 1 行、下端の 1 行、左端の 1 列、右端の 1 列を削除すればよいです。
入力例 2
3 4 #... .... ...#
出力例 2
#... .... ...#
この画像では、最上行、最下行、最左列、最右列のいずれにも黒いピクセルが含まれています。
したがってどの行や列も削除されず、元の画像をそのまま出力すればよいです。
入力例 3
5 6 ...... ...... ...#.. ...... ......
出力例 3
#
Score : 200 points
Problem Statement
There is a black-and-white image of height H pixels and width W pixels.
The color of the pixel at the i-th row from the top and j-th column from the left is given as a character C_{i,j}, where . represents white and # represents black.
From the top, bottom, left, and right edges of this image, remove rows and columns where all pixels are white. Specifically, perform the following operations in order:
- While the topmost row of the image is entirely white, repeat removing the topmost row.
- While the bottommost row of the image is entirely white, repeat removing the bottommost row.
- While the leftmost column of the image is entirely white, repeat removing the leftmost column.
- While the rightmost column of the image is entirely white, repeat removing the rightmost column.
Output the image after processing.
The given image contains at least one black pixel.
Constraints
- 1 \le H, W \le 50
- C_{i,j} is
.or#. - At least one black pixel exists.
Input
The input is given from Standard Input in the following format:
H W
C_{1,1}C_{1,2}\ldots C_{1,W}
C_{2,1}C_{2,2}\ldots C_{2,W}
\vdots
C_{H,1}C_{H,2}\ldots C_{H,W}
Output
Output the image after processing in the following format.
Here, h and w are the height and width of the image after processing, in pixels, respectively.
c_{i,j} is the character representing the color of the pixel at the i-th row from the top and j-th column from the left; c_{i,j} must be . if the pixel is white and # if it is black.
c_{1,1}c_{1,2}\ldots c_{1,w}
c_{2,1}c_{2,2}\ldots c_{2,w}
\vdots
c_{h,1}c_{h,2}\ldots c_{h,w}
Sample Input 1
4 5 ..... ..#.. .###. .....
Sample Output 1
.#. ###
You should remove one row from the top edge, one row from the bottom edge, one column from the left edge, and one column from the right edge.
Sample Input 2
3 4 #... .... ...#
Sample Output 2
#... .... ...#
In this image, all of the topmost row, bottommost row, leftmost column, and rightmost column contain black pixels.
Therefore, without removing any rows or columns, you should output the original image as is.
Sample Input 3
5 6 ...... ...... ...#.. ...... ......
Sample Output 3
#