Skip to content

Commit 432a7ac

Browse files
authoredMar 21, 2025
Merge pull request #1482 from emost22/feature/implementation
boj 5212 지구 온난화
2 parents ad70009 + ca3ac5b commit 432a7ac

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
 

‎구현/5212.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#define MAX 11
4+
using namespace std;
5+
6+
char list[MAX][MAX];
7+
bool chk[MAX][MAX];
8+
int direct[4][2] = { {0,1},{1,0},{0,-1},{-1,0} };
9+
int N, M;
10+
11+
bool isInRange(int x, int y) {
12+
return x >= 0 && y >= 0 && x < N && y < M;
13+
}
14+
15+
bool isBetweenWater(int x, int y) {
16+
int cnt = 0;
17+
for (int d = 0; d < 4; d++) {
18+
int nx = x + direct[d][0];
19+
int ny = y + direct[d][1];
20+
if (isInRange(nx, ny)) cnt += (list[nx][ny] == '.');
21+
else cnt++;
22+
}
23+
return cnt >= 3;
24+
}
25+
26+
void func() {
27+
for (int i = 0; i < N; i++) {
28+
for (int j = 0; j < M; j++) {
29+
if (list[i][j] == '.') continue;
30+
chk[i][j] = isBetweenWater(i, j);
31+
}
32+
}
33+
34+
int mnx = MAX;
35+
int mxx = 0;
36+
int mny = MAX;
37+
int mxy = 0;
38+
for (int i = 0; i < N; i++) {
39+
for (int j = 0; j < M; j++) {
40+
if (chk[i][j]) list[i][j] = '.';
41+
if (list[i][j] == 'X') {
42+
mnx = min(mnx, i);
43+
mxx = max(mxx, i);
44+
mny = min(mny, j);
45+
mxy = max(mxy, j);
46+
}
47+
}
48+
}
49+
50+
for (int i = mnx; i <= mxx; i++) {
51+
for (int j = mny; j <= mxy; j++) {
52+
cout << list[i][j];
53+
}
54+
cout << '\n';
55+
}
56+
}
57+
58+
void input() {
59+
cin >> N >> M;
60+
for (int i = 0; i < N; i++) {
61+
cin >> list[i];
62+
}
63+
}
64+
65+
int main() {
66+
cin.tie(NULL); cout.tie(NULL);
67+
ios::sync_with_stdio(false);
68+
69+
input();
70+
func();
71+
72+
return 0;
73+
}

0 commit comments

Comments
 (0)
Please sign in to comment.