Algorithm/PS
[1일 1알고] S4 10656 십자말풀이
Basaeng
2026. 3. 27. 15:38

https://www.acmicpc.net/problem/10656
오늘은 간단한 구현 문제입니다.
NxM격자가 주어지기 때문에 이차원 벡터를 사용해야겠지만 구분이 없는 문자열로 주어지기 때문에 벡터의 요소로 string을 사용하는 것으로 대신했습니다.
그리고 결과가 r, c 순서로 정렬되며 중복을 제거해야되기 때문에 set 자료형을 사용했습니다.
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin >> N >> M;
vector<string> v(N);
for (int i = 0; i < N; ++i)
{
string row;
cin >> v[i];
}
set<pair<int, int>> s;
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < M; ++j)
{
// 가로
if ((j == 0 || v[i][j - 1] == '#') && v[i][j] == '.')
{
int cnt = 1;
while (j + cnt < M && v[i][j + cnt] == '.')
{
++cnt;
}
if (cnt >= 3)
s.insert({ i + 1, j + 1 });
}
// 세로
if ((i == 0 || v[i-1][j] == '#') && v[i][j] == '.')
{
int cnt = 1;
while (i + cnt < N && v[i+cnt][j] == '.')
{
++cnt;
}
if (cnt >= 3)
s.insert({ i + 1, j + 1 });
}
}
}
cout << s.size() << '\n';
for (auto elem : s)
{
cout << elem.first << ' ' << elem.second << '\n';
}
return 0;
}