码迷,mamicode.com
首页 > 其他好文 > 详细

【codeforces】14A-Letter

时间:2018-04-20 21:59:47      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:const   c++   let   水题   com   pre   space   lan   output   

Letter

http://codeforces.com/problemset/problem/14/A

题意:就是要输出包含所有  *  的最小矩阵,其中题中input中一定会有* 所以不用担心这个问题

Input
6 7
.......
..***..
..*....
..***..
..*....
..***..
Output
***
*..
***
*..
***

思路:找边界即可,水题。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int main()
{
    
    char a[55][55];
    int n,m;
    
    while(cin>>n>>m){
        int mini=inf,minj=inf,maxi=0,maxj=0;
        int i,j;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                cin>>a[i][j];
                if(a[i][j]==*){
                    mini=min(mini,i);
                    minj=min(minj,j);
                    maxi=max(maxi,i);
                    maxj=max(maxj,j);
                }
            }
        }
        for(i=mini;i<=maxi;i++){
            for(j=minj;j<=maxj;j++){
                cout<<a[i][j];
            }
            cout<<endl;
        }
    }


    return 0;
}

 

【codeforces】14A-Letter

标签:const   c++   let   水题   com   pre   space   lan   output   

原文地址:https://www.cnblogs.com/Kohinur/p/8893349.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!