Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created October 14, 2017 08:09
Show Gist options
  • Save henrybear327/f3ec5503091fdb2168342c92be8ba515 to your computer and use it in GitHub Desktop.
Save henrybear327/f3ec5503091fdb2168342c92be8ba515 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
const int S = 4;
const int INA = 2; // inactive
const int ADA = 0;
const int XY = 1;
const int NON = 3; // nonreachable
const int ACT = 5; // active
int sx, sy;
int A[8][8];
int Z[8][8];
bool xy_check(int tx, int ty) {
for (int x = min(sx, tx); x <= max(sx, tx); x++) {
if (A[x][sy] == INA) {
return false;
}
}
for (int y = min(sy, ty); y <= max(sy, ty); y++) {
if (A[tx][y] == INA) {
return false;
}
}
return true;
}
bool ada_check(int tx, int ty) {
for (int x = min(sx, tx); x <= max(sx, tx); x++) {
for (int y = min(sy, ty); y <= max(sy, ty); y++) {
if (A[x][y] == INA) {
return false;
}
}
}
return true;
}
void print(int a[8][8]) {
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
cout << a[x][y];
}
cout << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
while (cin >> s) {
if (s == "0") break;
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
Z[x][y] = NON;
}
}
for (int i = 0; i < 64; i++) {
int y = i / 8;
int x = i % 8;
if (s[i] == '2') {
A[x][y] = S;
Z[x][y] = S;
sx = x;
sy = y;
} else if (s[i] == '1') {
A[x][y] = INA;
Z[x][y] = INA;
} else {
A[x][y] = ACT;
}
}
// print(A);
// cout << endl;
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
if (x == sx && y == sy) continue;
if (xy_check(x, y)) {
Z[x][y] = XY;
}
}
}
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
if (x == sx && y == sy) continue;
if (ada_check(x, y)) {
Z[x][y] = ADA;
}
}
}
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
cout << Z[x][y];
}
}
cout << endl;
// print(Z);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment