반응형
풀이
- 따로 어려운 부분은 없었고, 단순히 문제 이해가 처음에는 안되었는데
- 그냥 "단순히 선이 이어져 있으면, 그게 하나의 타일이다" 라고 설명했으면
- 더 쉽게 이해했을듯 하다... ㅋㅋ
- 무튼 그래서 mtx에 대해 기본 타입에선 "-" 만 체크하고
- 이후엔 범위를 변경 후 "ㅣ" 만 체크해서 카운팅하여 해결.
import java.io.*;
import java.util.*;
public class _1388 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int result = 0;
String now;
int[] NM = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
String[][] mtx = new String[NM[0]][NM[1]];
for (int i=0; i<NM[0]; i++) {
String inp = br.readLine();
for (int j=0; j<NM[1]; j++) mtx[i][j] = String.valueOf(inp.charAt(j));
}
// 가로 세로 각각 찾기(정사각형이 아니어서)
for (int i=0; i<NM[0]; i++) {
now = "";
for (int j=0; j<NM[1]; j++) {
if (mtx[i][j].equals("-") && !now.equals("-")) {
now = "-";
result++;
}
else if (!mtx[i][j].equals("-")) now = mtx[i][j];
}
}
for (int i=0; i<NM[1]; i++) {
now = "";
for (int j=0; j<NM[0]; j++) {
if (mtx[j][i].equals("|") && !now.equals("|")) {
now = "|";
result++;
}
else if (!mtx[j][i].equals("|")) now = mtx[j][i];
}
}
System.out.println(result);
}
}
'알고리즘' 카테고리의 다른 글
[백준, 자바, 10825번] 국영수 (2차원 배열 정렬 문제) (0) | 2024.10.11 |
---|---|
[백준, 자바, 17204번] 죽음의 게임 (1) | 2024.10.11 |
[백준, 자바, 7562번] 나이트의 이동 (0) | 2024.10.10 |
[백준, 자바, 16173번] 점프왕 쩰리 (Small) (0) | 2024.10.10 |
[백준, 자바, 11403번] 경로 찾기 (0) | 2024.10.10 |