#include <stdio.h>
#define BLOCK 1
#define SIZE 5
int mirror[SIZE][SIZE] = {
{ 0, 0, 0, 0, 0},
{ 0, 1, 1, 1, 0},
{ 0, 1, 0, 1, 0},
{ 0, 1, 1, 1, 0},
{ 0, 0, 0, 0, 1},
};
int process(void);
int checkIsRect(int x, int y);
int main (int argc, char **argv) {
int count = process();
printf ("%d\n", count);
return 0;
}
int process(void) {
int count = 0;
int i = 0, j = 0;
for ( i = 0; i < SIZE; i++) {
for ( j = 0; j < SIZE; j++ ) {
if ( mirror[i][j] == BLOCK ) {
count += checkIsRect(j, i);
}
}
}
return count;
}
int checkIsRect(int posX, int posY) {
int count = 0;
int isEnd = 0;
int x = posX;
int y = posY;
int width = 0;
int height = 0;
int x2 = posX;
int y2 = posY;
//int width2 = 0;
//int height2 = 0;
/* Check Right -> Check Down */
do {
mirror[y][x] = 0;
x++;
width++;
} while (x < SIZE && mirror[y][x] == 1);
x--;
do {
mirror[y][x] = 0;
y++;
height++;
} while (y < SIZE && mirror[y][x] == 1);
y--;
/* Check Down -> Check Left */
do {
mirror[y2][x2] = 0;
y2++;
//height2++;
} while (y2 < SIZE && mirror[y2][x2] == 1);
y2--;
do {
mirror[y2][x2] = 0;
x2++;
//width2++;
} while (x2 < SIZE && mirror[y2][x2] == 1);
// Already mirror[y2][x2] == 0
// Because x == x2, y == y2
// No need to x2--;
if ( x == x2 && y == y2 && width >= 3 && height >= 3 ) {
count = 1;
}
//printf ("x: %d y: %d x2: %d y2: %d width: %d height: %d \n", x, y, x2, y2, width, height);
return count;
}