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;
}
- [图解DS基础概念]Critical value,Alpha,Z-score,P-value 关系
- Docker系列教程02-Docker安装(CentOS7/Ubuntu/macOS/Windows)
- Docker系列课程01-Docker简介
- document.ready 与 window.onload的区别
- react+redux+webpack教程1
- LINC switch系列之配置与运行
- video.js支持m3u8格式直播
- 直播视频在微信内自动播放
- yield 原理篇
- 开启聊天机器人模式
- Linux 后台服务
- gulp rev manifest 添加目录前缀
- 【LEETCODE】模拟面试-294.Flip Game II
- 基于CentOS7安装Jupyter Notebook
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Laravel 之url参数,获取路由参数的例子
- PHP call_user_func和call_user_func_array函数的简单理解与应用分析
- PHP常用函数之获取汉字首字母功能示例
- 浅谈laravel-admin form中的数据,在提交后,保存前,获取并进行编辑
- tp5 实现列表数据根据状态排序
- mac pecl 安装php7.1扩展教程
- tp5.1 实现setInc字段自动加1
- Laravel 前端资源配置教程
- laravel框架语言包拓展实现方法分析
- PHP使用JpGraph绘制折线图操作示例【附源码下载】
- Laravel Eloquent分表方法并使用模型关联的实现
- 关于laravel模板中生成URL的几种模式总结
- Laravel基础-关于引入公共文件的两种方式
- Laravel框架Blade模板简介及模板继承用法分析
- 基于Laravel 多个中间件的执行顺序详解