Advertisement
Goga21

Untitled

Sep 2nd, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. signed main() {
  8.     ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
  9.     int n, m;
  10.     cin >> n >> m;
  11.  
  12.     vector<vector<char>> v(n, vector<char> (m));
  13.     string ans;
  14.     string f;
  15.  
  16.     for(int i = 0; i < n; ++i){
  17.         bool q = true;
  18.         for(int j = 0; j < m; ++j){
  19.             cin >> v[i][j];
  20.             if(v[i][j] == '#'){
  21.                 q = false;
  22.             }
  23.         }
  24.         if(q){
  25.             for(int j = 0; j < m; ++j){
  26.                 f += v[i][j];
  27.             }
  28.  
  29.             if((ans > f || ans.empty()) && f.size() >= 2){
  30.                 ans = f;
  31.             }
  32.             //cout << f << '\n';
  33.             f = "";
  34.         }
  35.     }
  36.  
  37.     for(int i = 0; i < m; ++i){
  38.         bool q = true;
  39.         for(int j = 0; j < n; ++j){
  40.             if(v[j][i] == '#'){
  41.                 q = false;
  42.                 break;
  43.             }
  44.         }
  45.  
  46.         if(q){
  47.             for(int j = 0; j < n; ++j){
  48.                 f += v[j][i];
  49.             }
  50.             if((ans > f || ans.empty()) && f.size() >= 2){
  51.                 ans = f;
  52.             }
  53.             //cout << f << '\n';
  54.             f = "";
  55.         }
  56.     }
  57.  
  58.     cout << ans;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement