Repository navigation
Expand file tree
/
Copy pathProblemC.java
More file actions
112 lines (101 loc) · 1.98 KB
/
Copy pathProblemC.java
File metadata and controls
112 lines (101 loc) · 1.98 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package codeforce;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ProblemC {
private static int[][] arr = new int[6][6];
static {
for(int i = 0; i < arr.length; i++) {
arr[0][i] = 9;
arr[i][0] = 9;
arr[5][i] = 9;
arr[i][5] = 9;
}
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
for (char c : s.toCharArray()) {
go(c - 48);
detect();
}
printArray();
}
public static void printArray() {
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < arr[0].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
public static void deleteX(int x) {
for(int i = 1; i < 5; i++) {
arr[x][i] = 0;
}
}
public static void deleteY(int y) {
for(int i = 1; i < 5; i++) {
arr[i][y] = 0;
}
}
public static void go(int i) {
if(i == 0) {
go0();
}
else {
go1();
}
}
public static void go0() {
for(int i = 1; i < 5; i++) {
for(int j = 1; j < 5; j++) {
if(arr[i][j] == 0 && arr[i+1][j] == 0) {
arr[i][j] = 1;
arr[i+1][j] = 1;
System.out.println(i+ " " + j);
return;
}
}
}
}
public static void go1() {
for(int i = 1; i < 5; i++) {
for(int j = 1; j < 5; j++) {
if(arr[i][j] == 0 && arr[i][j+1] == 0) {
arr[i][j] = 1;
arr[i][j+1] = 1;
System.out.println(i+ " " + j);
return;
}
}
}
}
public static void detect() {
detectX();
detectY();
}
public static void detectX() {
for(int i = 1; i < 5; i++) {
int check = 1;
for(int j = 1; j < 5; j++) {
check &= arr[i][j];
}
if(check == 1) {
deleteX(i);
}
}
}
public static void detectY() {
for(int i = 1; i < 5; i++) {
int check = 1;
for(int j = 1; j < 5; j++) {
check &= arr[j][i];
}
if(check == 1) {
deleteY(i);
}
}
}
}