day 4 part 2

magical 2024-12-04 06:22:21 +00:00
parent 5cb39af7b8
commit 6f080958ac
1 changed files with 22 additions and 2 deletions

View File

@ -109,10 +109,30 @@ int solve(struct grid *g) {
return 0;
}
int solve2(struct grid *g) {
int x, y;
int count = 0;
const char *word = "MAS";
for (y = 0; y < g->y; y++)
for (x = 0; x < g->x; x++) {
if (g->A[y][x] != 'A') continue;
int mas = 0;
if (search(g, x-1, y-1, +1, +1, word)) { mas++; }
if (search(g, x+1, y+1, -1, -1, word)) { mas++; }
if (search(g, x-1, y+1, +1, -1, word)) { mas++; }
if (search(g, x+1, y-1, -1, +1, word)) { mas++; }
if (mas == 2) { count++; }
}
printf("%d\n", count);
return 0;
}
int main() {
struct grid g;
//readfile("sample2.in", &g);
readfile("input", &g);
readfile("sample2.in", &g);
//readfile("input", &g);
printf("%d %d\n", g.x, g.y);
solve(&g);
solve2(&g);
}