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;
- for(int i = 0; i < n; ++i){
- string q = "";
- for(int j = 0; j < m; ++j){
- cin >> v[i][j];
- if(v[i][j] == '#'){
- if(q.size() >= 2 && (ans > q || ans.empty())){
- ans = q;
- }
- q = "";
- }else{
- q += v[i][j];
- }
- }
- if(!q.empty()){
- if(q.size() >= 2 && (ans > q || ans.empty())){
- ans = q;
- }
- }
- }
- for(int i = 0; i < m; ++i){
- string q = "";
- for(int j = 0; j < n; ++j){
- if(v[j][i] == '#'){
- if(q.size() >= 2 && (ans > q || ans.empty())){
- ans = q;
- }
- q = "";
- }else{
- q += v[j][i];
- }
- }
- if(!q.empty()){
- if(q.size() >= 2 && (ans > q || ans.empty())){
- ans = q;
- }
- }
- }
- cout << ans << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement