1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "stdio.h"
- int tree_count(char[323][31], int, int);
- int main() {
- char lines[323][31];
- int i = 0;
- while (scanf("%s", lines[i++]) == 1)
- ;
- long product = 1;
- product *= tree_count(lines, 3, 1);
- printf("Answer 1: %ld\n", product);
- product *= tree_count(lines, 1, 1);
- product *= tree_count(lines, 5, 1);
- product *= tree_count(lines, 7, 1);
- product *= tree_count(lines, 1, 2);
- printf("Answer 2: %ld\n", product);
- }
- int tree_count(char lines[323][31], int x_inc, int y_inc) {
- int x = 0, y = 0;
- int trees = 0;
- while (y < 323) {
- if (lines[y][x] == '#')
- trees++;
- y += y_inc; x += x_inc;
- x %= 31;
- }
- return trees;
- }
|