int height;
int width;
int[][] a;
this.height = height;
this.width = height;
a = new int[height][width];
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
a[i][j] = 0;
}
public void printBox() {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++)
}
}
public void plus(int[] i, int[] j) {
for (int n = 0; n < i.length; n++)
plus(i[n], j[n]);
}
public void plus(int i, int j) {
if (inBounds(i) && inBounds(j))
a[i][j] = (a[i][j] + 1) % 2;
if (inBounds(i - 1) && inBounds(j))
a[i - 1][j] = (a[i - 1][j] + 1) % 2;
if (inBounds(i) && inBounds(j - 1))
a[i][j - 1] = (a[i][j - 1] + 1) % 2;
if (inBounds(i + 1) && inBounds(j))
a[i + 1][j] = (a[i + 1][j] + 1) % 2;
if (inBounds(i) && inBounds(j + 1))
a[i][j + 1] = (a[i][j + 1] + 1) % 2;
}
public boolean inBounds(int n) {
return n >= 0 && n < height;
}
}
public class Main
{
public static void main
(String[] args
) { b.printBox();
int[] i = { 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4 };
int[] j = { 0, 2, 4, 1, 3, 0, 4, 1, 3, 0, 2, 4 };
b.plus(i, j);
b.printBox();
}
}
Y2xhc3MgQm94IHsKCWludCBoZWlnaHQ7CglpbnQgd2lkdGg7CglpbnRbXVtdIGE7CgoJcHVibGljIEJveChpbnQgaGVpZ2h0KSB7CgkJdGhpcy5oZWlnaHQgPSBoZWlnaHQ7CgkJdGhpcy53aWR0aCA9IGhlaWdodDsKCQlhID0gbmV3IGludFtoZWlnaHRdW3dpZHRoXTsKCQlmb3IgKGludCBpID0gMDsgaSA8IGhlaWdodDsgaSsrKQoJCQlmb3IgKGludCBqID0gMDsgaiA8IHdpZHRoOyBqKyspCgkJCQlhW2ldW2pdID0gMDsKCX0KCglwdWJsaWMgdm9pZCBwcmludEJveCgpIHsKCQlmb3IgKGludCBpID0gMDsgaSA8IGhlaWdodDsgaSsrKSB7CgkJCWZvciAoaW50IGogPSAwOyBqIDwgd2lkdGg7IGorK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