首页 > 其他 > 详细

【codeforces】14A-Letter

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!