1일1알

백준 3005번 크로스워드 퍼즐 쳐다보기 C++ 본문

알고리즘

백준 3005번 크로스워드 퍼즐 쳐다보기 C++

영춘권의달인 2023. 1. 7. 11:50

https://www.acmicpc.net/problem/3005

 

3005번: 크로스워드 퍼즐 쳐다보기

첫째 줄에 R과 C (2 ≤ R, C ≤ 20)가 주어진다. R는 행의 개수, C는 열의 개수이다. 그 다음 R개의 줄엔 C개의 문자가 포함되어 있다. 각 문자는 영어 알파벳 소문자 또는 '#'이며, '#'인 경우에는 막혀

www.acmicpc.net

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>

using namespace std;
using int64 = long long; 

int r, c;
vector<vector<char>> v;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> r >> c;
    v = vector<vector<char>>(r, vector<char>(c));
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> v[i][j];
        }
    }
    set<string> s;
    for (int i = 0; i < r; i++) {
        string str = "";
        for (int j = 0; j < c; j++) {
            if (v[i][j] == '#') {
                if (str.length() >= 2) s.insert(str);
                str = "";
                continue;
            }
            str += v[i][j];
        }
        if (str.length() >= 2) s.insert(str);
    }
    for (int i = 0; i < c; i++) {
        string str = "";
        for (int j = 0; j < r; j++) {
            if (v[j][i] == '#') {
                if (str.length() >= 2) s.insert(str);
                str = "";
                continue;
            }
            str += v[j][i];
        }
        if (str.length() >= 2) s.insert(str);
    }
    string ans = *s.begin();
    cout << ans;
}

'알고리즘' 카테고리의 다른 글

백준 17391번 무한부스터 C++  (0) 2023.01.09
백준 2785번 체인 C++  (1) 2023.01.08
백준 16437번 양 구출 작전 C++  (0) 2023.01.06
백준 14923번 미로 탈출 C++  (0) 2023.01.05
백준 13903번 출근 C++  (0) 2023.01.04