专栏首页glm的全栈学习之路Codeforces Beta Round #14 (Div. 2)A. Letter

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;
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 2018-2019 ICPC, NEERC, Southern Subregional Contest D. Garbage Disposal

    Enough is enough. Too many times it happened that Vasya forgot to dispose of gar...

    glm233
  • Codeforces Round #622 (Div. 2) A.Fast Food Restaurant

    Tired of boring office work, Denis decided to open a fast food restaurant.

    glm233
  • Codeforces Round #615 (Div. 3) F. Three Paths on a Tree

    You are given an unweighted tree with nn vertices. Recall that a tree is a conne...

    glm233
  • uva-----11292 The Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, ...

    Gxjun
  • UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, ...

    Angel_Kitty
  • spark 2.3 导致driver OOM的一个SparkPlanGraphWrapper源码的bug

    长话短说,我们部门一个同事找到我,说他的spark 2.3 structured streaming程序频繁报OOM,从来没有坚持过超过三四天的,叫帮看一下。 ...

    老白
  • 医学图像分割--Segmentation of Medical Ultrasound Images...

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangjunhit/article/de...

    用户1148525
  • HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】

    Least Common Multiple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65...

    Angel_Kitty
  • 史上最全的vim快捷键文档/手册/大全/帮助/指南

    Tip Run vimtutor in a terminal to learn the first Vim commands.

    sunsky
  • Facebook开源Torchnet加速深度学习,Caffe 、TensorFlow将可用

    Facebook宣布开源用于简化深度学习、加速开发的软件Torchnet。 用Lua编写 提供样板代码、关键抽象和参考实现,可以聚合分拆重用,...

    CSDN技术头条

扫码关注云+社区

领取腾讯云代金券