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;
}
- TensorFlow从0到1丨第2篇:TensorFlow核心编程
- AngularJS中的按需加载ocLazyLoad
- AngularJS driective 封装 自动滚动插件
- java类过滤器,防止页面SQL注入
- Web项目添加Maven支持
- Jquery 获取第一个子元素
- Dropwizard框架入门
- Java 解析Excel文件为JSON
- SQL语句大小写是否区分的问题,批量修改整个数据库所有表所有字段大小写
- CentOS 6.5 安装nginx 1.6.3
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- MyBatis两张表字段名相同产生的问题
- mongo 3.0 备份和还原数据库 ,及too many positional arguments错误
- AngularJs HTTP响应拦截器实现登陆、权限校验
- 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 数组属性和方法
- 小书MybatisPlus第4篇-表格分页与下拉分页查询
- 小书MybatisPlus第3篇-自定义SQL
- Nginx + Spring Boot 实现负载均衡
- 小书MybatisPlus第2篇-条件构造器的应用及总结
- 一个案例演示 Spring Security 中粒度超细的权限控制!
- 信息收集之主机发现:nmap
- 文本文件逐行处理–用java8 Stream流的方式
- 使用java8API遍历过滤文件目录及子目录及隐藏文件
- 使用位运算、值交换等方式反转java字符串-共四种方法
- 精讲RestTemplate第2篇-多种底层HTTP客户端类库的切换
- 精讲RestTemplate第1篇-在Spring或非Spring环境下如何使用
- 在图中添加多边形
- 设置坐标轴刻度的位置和样式
- OkHttp透明压缩,收获性能10倍,外加故障一枚
- 体验spring-boot-devtools热部署,流畅且不失强大