A. Letter

原创 2013年12月04日 22:28:53

time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

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 test(s)
input
6 7
.......
..***..
..*....
..***..
..*....
..***..
output
***
*..
***
*..
***
input
3 3
***
*.*
***
output
***
*.*
***

解题说明:此题是一道图形题,要求找到包含所有星号的最小的矩形,可以通过遍历图中的每个位置,确定出星号的位置,最终得出一个矩形。


#include<stdio.h>

int main()
{
	char dizi[55][55],c;
	int k,n,m,i,j,maxx=-999999,maxy=-999999,minx=99999,miny=999999,sayac=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%s",dizi[i]);
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(dizi[i][j]=='*')
			{
				if(i<=minx)
				{
					minx=i;
				}
				if(i>=maxx)
				{
					maxx=i;
				}
				if(j<=miny)
				{
					miny=j;
				}
				if(j>=maxy)
				{
					maxy=j;
				}
			}
		}
	}
	for(i=minx;i<=maxx;i++)
	{
		for(j=miny;j<=maxy;j++)
		{
			printf("%c",dizi[i][j]);
		}
		printf("\n");
	}
	return 0;
}


版权声明: 举报

相关文章推荐

Letter to a Young Developer

导读:本文是从作者Avdi Grimm发表的一篇博客《 Letter to a Young Developer》翻译而来。文中给想要成为一名成功的程序员提供了几点建议,供大家学习、参考。 文章内容如...

A Love Letter To Josephine

我收到了你的信,我祟拜的心上人。你的信使我充满了欢乐……自从与你分手以后,我一直闷闷不乐,愁眉不展。我唯一的幸福就是伴随着你。你的吻给了我无限的思索和回味,还有你的泪水和甜蜜的嫉妒。我迷人的约瑟芬的魅...

精选:深入理解 Docker 内部原理及网络配置

网络绝对是任何系统的核心,对于容器而言也是如此。Docker 作为目前最火的轻量级容器技术,有很多令人称道的功能,如 Docker 的镜像管理。然而,Docker的网络一直以来都比较薄弱,所以我们有必要深入了解Docker的网络知识,以满足更高的网络需求。

Letter to a Young Developer

导读:本文是从作者Avdi Grimm发表的一篇博客《 Letter to a Young Developer》翻译而来。文中给想要成为一名成功的程序员提供了几点建议,供大家学习、参考。 文章内...

Letter to a Young Developer

I’ve been getting some emails from young developers wanting to “level up” as programmers. I’m defini...
  • rudyn
  • rudyn
  • 2011-09-16 08:27
  • 129

Letter Combinations of a Phone Number,LeetCode

题目内容就不赘述了,网上看到的方法几乎清一色用到了递归,而我本人不怎么喜(hui)欢递归,略微尝试了一下就放弃了,然后没有用递归同样写出了程序,虽然代码要长一些,复杂一些。 先上代码,已通过。 ...

LeetCode--Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent. A ...

leetcode-letter combination of a phone number

Given a digit string, return all possible letter combinations that the number could represent. A ...

Leetcode: Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent. A ma...

Letter Combinations of a Phone Number

每日算法——leetcode系列问题 3Sum ClosestDifficulty: Medium Given a digit string, return all possible letter...

17. Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent. A ...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)