Codeforces Beta Round #14 (Div. 2)A. Letter

时间:2022-07-25
本文章向大家介绍Codeforces Beta Round #14 (Div. 2)A. Letter,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows 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

Copy

6 7
.......
..***..
..*....
..***..
..*....
..***..

output

Copy

***
*..
***
*..
***

input

Copy

3 3
***
*.*
***

output

Copy

***
*.*
***

简单模拟即可

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 55
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
ll n,m;
char s[maxn][maxn];
int main()
{
    cin>>n>>m;
    ll hmax=-inf,lmax=-inf,hmin=inf,lmin=inf;
    for(rg i=1;i<=n;i++)
    {
        for(rg j=1;j<=m;j++)
        {
            cin>>s[i][j];
            if(s[i][j]=='*')
            {
                hmax=max(hmax,i);
                lmax=max(lmax,j);
                lmin=min(lmin,j);
                hmin=min(hmin,i);
            }
        }
    }
    for(rg i=hmin;i<=hmax;i++)
    {
        for(rg j=lmin;j<=lmax;j++)
        {
            cout<<s[i][j];
        }cout<<endl;
    }
   	return 0;
}