Advertisement
Goga21

Untitled

Sep 2nd, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 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.  
  15.     for(int i = 0; i < n; ++i){
  16.         string q = "";
  17.         for(int j = 0; j < m; ++j){
  18.             cin >> v[i][j];
  19.             if(v[i][j] == '#'){
  20.                 if(q.size() >= 2 && (ans > q || ans.empty())){
  21.                     ans = q;
  22.                 }
  23.                 q = "";
  24.             }else{
  25.                 q += v[i][j];
  26.             }
  27.         }
  28.         if(!q.empty()){
  29.             if(q.size() >= 2 && (ans > q || ans.empty())){
  30.                 ans = q;
  31.             }
  32.         }
  33.        
  34.     }
  35.  
  36.     for(int i = 0; i < m; ++i){
  37.         string q = "";
  38.         for(int j = 0; j < n; ++j){
  39.             if(v[j][i] == '#'){
  40.                 if(q.size() >= 2 && (ans > q || ans.empty())){
  41.                     ans = q;
  42.                 }
  43.                 q = "";
  44.             }else{
  45.                 q += v[j][i];
  46.             }
  47.         }
  48.         if(!q.empty()){
  49.             if(q.size() >= 2 && (ans > q || ans.empty())){
  50.                 ans = q;
  51.             }
  52.         }
  53.     }
  54.  
  55.     cout << ans << '\n';
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement