diff options
Diffstat (limited to '12.c')
-rw-r--r-- | 12.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> struct pos { @@ -86,14 +87,26 @@ tryvisit(unsigned char * range, int cols, int rows, struct pos const * from, int int -main() +main(int argc, char ** argv) { + int part = 1; unsigned char * range, * p; size_t rangesize, rangelen, bytes; int cols, rows; struct pos * front; int steps; + while ((steps = getopt(argc, argv, "p:")) != -1) { + switch (steps) { + case 'p': + part = atoi(optarg); + break; + + default: + return -1; + } + } + // Read hill range rangesize = BUFSIZ; rangelen = 0; @@ -141,9 +154,12 @@ main() struct pos * loc; for (loc = front; loc != NULL; loc = loc->next) { - if ((range[loc->x + loc->y * cols] & 0x7F) == 'S') + if (part == 1 && (range[loc->x + loc->y * cols] & 0x7F) == 'S') // We found the start point! break; + if (part == 2 && height(range[loc->x + loc->y * cols]) == 'a') + // We found a low point + break; if (tryvisit(range, cols, rows, loc, -1, 0)) nextfront = pos_create(loc->x - 1, loc->y, nextfront); |