Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main() {
- ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
- int n, m;
- cin >> n >> m;
- vector<vector<char>> v(n, vector<char> (m));
- string ans;
- string f;
- for(int i = 0; i < n; ++i){
- bool q = true;
- for(int j = 0; j < m; ++j){
- cin >> v[i][j];
- if(v[i][j] == '#'){
- q = false;
- }
- }
- if(q){
- for(int j = 0; j < m; ++j){
- f += v[i][j];
- }
- if((ans > f || ans.empty()) && f.size() >= 2){
- ans = f;
- }
- //cout << f << '\n';
- f = "";
- }
- }
- for(int i = 0; i < m; ++i){
- bool q = true;
- for(int j = 0; j < n; ++j){
- if(v[j][i] == '#'){
- q = false;
- break;
- }
- }
- if(q){
- for(int j = 0; j < n; ++j){
- f += v[j][i];
- }
- if((ans > f || ans.empty()) && f.size() >= 2){
- ans = f;
- }
- //cout << f << '\n';
- f = "";
- }
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement