首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Codeforces Beta Round #14 (Div. 2)A. Letter

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

作者头像
glm233
发布2020-09-28 10:43:28
发布2020-09-28 10:43:28
6780
举报

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

代码语言:javascript
复制
6 7
.......
..***..
..*....
..***..
..*....
..***..

output

Copy

代码语言:javascript
复制
***
*..
***
*..
***

input

Copy

代码语言:javascript
复制
3 3
***
*.*
***

output

Copy

代码语言:javascript
复制
***
*.*
***

简单模拟即可

代码语言:javascript
复制
// 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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/08/24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档