A. Letter

题目连接:

http://www.codeforces.com/contest/14/problem/A

Description

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.

Sample Input

6 7

.......

....

..
....

..
..

..
....

..***..

Sample Output


*..


*..


Hint

题意

让你找到最小的矩形,使得这个矩形能够包含所有的*

题解:

水题嘛,记录最左上角和最右下角就好了。

代码

#include<bits/stdc++.h>
using namespace std;
string s[55];
int main(){
int n,m;
scanf("%d%d",&n,&m);
int ix=1e9,iy=1e9,ax=0,ay=0;
for(int i=0;i<n;i++){
cin>>s[i];
for(int j=0;j<m;j++){
if(s[i][j]=='*')
ix=min(ix,i),iy=min(iy,j),ax=max(ax,i),ay=max(ay,j);
}
}
for(int i=ix;i<=ax;i++){
for(int j=iy;j<=ay;j++){
cout<<s[i][j];
}
cout<<endl;
}
}

最新文章

  1. wp8 入门到精通 仿美拍评论黑白列表思路
  2. spark转换集合为RDD
  3. Android NDK之JNI陷阱
  4. iOS开发UI篇—字典转模型
  5. 原生javascript加载运行
  6. C#中的结构体与类的区别
  7. NSLog说明
  8. 使用pdb调试python
  9. openSource clouds
  10. C++编程规范之19:总是初始化变量
  11. ubuntu的网络配置
  12. 深入理解Lambda函数及其用法
  13. 时间字符串格式化 js
  14. java解答:有17个人围成一圈(编号0~16),从第0号的人开始从1报数,凡报到3的倍数的人离开圈子,然后再数下去,直到最后只剩下一个人为止,问此人原来的位置是多少号?
  15. loj#2483. 「CEOI2017」Building Bridges 斜率优化 cdq分治
  16. linux下混杂模式
  17. D3.js(v3)+react框架 基础部分之数据绑定及其工作过程与绑定顺序
  18. Qt5.3.1 静态编译的configure
  19. Skyline开发4-IProject接口
  20. SMTP——MIME

热门文章

  1. 何凯文每日一句打卡||DAY9
  2. 20155339 2016-2017-2 《Java程序设计》第6周学习总结
  3. Android利用LocalSocket实现Java端进程与C端进程之间的IPC
  4. Ajax和jsonp区别
  5. 各种卷积类型Convolution
  6. 针对Jigsaw勒索软件的解锁工具
  7. 洛谷 P3320: bzoj 3991: LOJ 2182: [SDOI2015]寻宝游戏
  8. ubuntu16.04系统搜狗输入法的安装
  9. 【转载】chmod命令详解
  10. Python学习二|Python的一些疑问