-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacmicpc_2667.java
More file actions
69 lines (68 loc) · 1.85 KB
/
acmicpc_2667.java
File metadata and controls
69 lines (68 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
public class acmicpc_2667 {
public static void main(String[] args) throws Exception {
//배열 생성 및 값 할당
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt((br.readLine()));
int [][] map = new int [N+2][N+2];
int [][] visited = new int [N+2][N+2];
int danji = 0;
for (int i=1; i<N+1; i++) {
String temp = br.readLine();
for (int j=1; j<N+1; j++) {
map[i][j] = temp.charAt(j-1)-'0';
}
}
//배열 탐색
int count = 0; int [] co = new int [N*N];
for (int i = 1; i < map.length; i++) {
for (int j = 1; j < map.length; j++) {
if (map[i][j] == 1) {
System.out.printf("%d %d\t",i,j);
map[i][j] = 0;
if (map[i-1][j] == 0 && map[i+1][j] == 0 && map[i][j-1] == 0 && map[i][j+1] == 0) {
danji+=1;
co[count] = count;
count = 0;
System.out.println();
for (int l = 0; l < map.length; l++) {
System.out.println(Arrays.toString(map[l]));
}
} else if (map[i][j-1] == 1) {
System.out.println("j-1");
j-=2;
count++;
} else if (map[i][j+1] == 1) {
System.out.println("j+1");
count++;
} else if (map[i-1][j] == 1) {
System.out.println("i-1");
i--;
j--;
count++;
} else if (map[i+1][j] == 1) {
System.out.println("i+1");
i++;
j--;
count++;
}
}
}
}
// System.out.println(danji);
// for (int i = 0; i < co.length; i++) {
// if (co[i] > 0) {
// System.out.println(co[i]);
// }
// }
//출력
// System.out.println();
// for (int i = 0; i < map.length; i++) {
// System.out.println(Arrays.toString(map[i]));
// }
}//eom
}//eoc