zoukankan      html  css  js  c++  java
  • Codeforces Beta Round #14 (Div. 2) A. Letter 水题

    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;
        }
    }
  • 相关阅读:
    【知识总结】数学必修二立体几何总结
    【知识总结】数学必修四、必修五三角函数公式总结
    Apache【第一篇】安装
    Nginx【第一篇】安装
    lsb_release 提示命令不存在
    yum 命令提示语法错误
    MySQL【第三篇】数据类型
    MySQL【第二篇】基本命令
    SecureCRT 中 python 命令行使用退格键(backspace)出现 ^H 解决办法
    MySQL【第一篇】安装
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5767667.html
Copyright © 2011-2022 走看看