letter

 avatar
jackoup
c_cpp
a year ago
818 B
3
Indexable
CodeForces
#include <iostream>

using namespace std;
void fio() {
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
}

int main() {
    fio();
    int n;cin>>n;
    int m;cin>>m;
    char arr[n][m];
    int minColumn = m,maxColumn =-1,minRow=n,maxRow=-1;
    for(int i =0;i<n;i++) {
        for(int j =0;j<m;j++) {
            cin>>arr[i][j];
            if(arr[i][j] == '*') {
                minColumn = min(minColumn, j);
                maxColumn = max(maxColumn,j);

                maxRow = max(maxRow,i);
                minRow = min(minRow,i);
            }
        }
    }

    for(int i = minRow;i<=maxRow;i++){
        for(int j = minColumn;j<=maxColumn;j++ ){
            cout<<arr[i][j];;
        }
        if(i != maxRow)
            cout<<"\n";
    }

    return 0;
    }
Editor is loading...
Leave a Comment