14ALetter

来源:互联网 发布:种子软件哪个好 编辑:程序博客网 时间:2024/06/01 10:46
A. Letter
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with nrows and m columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides.

Input

The first line of the input data contains numbers n and m (1 ≤ n, m ≤ 50), n — amount of lines, and m — amount of columns on Bob's sheet. The following n lines contain m characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square.

Output

Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.

Examples
input
6 7.........***....*......***....*......***..
output
****..****..***
input
3 3****.****
output
****.****

题意: 找出有*的行列,输出。直接找第一个*的行列坐标和最后一个*的行列坐标。

也就是找*最小横坐标和纵坐标是第一颗,最大横坐标和最大纵坐标是最后一颗*。

#include<bits/stdc++.h>using namespace std;const int N=60;int main(){    char a[N][N];    int n,m,sx,sy,ex,ey,cnt;    while(cin>>n>>m)    {        sx=100,ex=-100,sy=100,ey=-100;        for(int i=0; i<n; i++)            for(int j=0; j<m; j++)            {                cin>>a[i][j];                if(a[i][j]=='*')                {                    sx=min(sx,i);                    sy=min(sy,j);                    ex=max(ex,i);                    ey=max(ey,j);                }            }        for(int i=sx; i<=ex; i++)            for(int j=sy; j<=ey+1; j++)                printf("%c",j==ey+1?'\n':a[i][j]);    }    return 0;}