3.c 730 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "stdio.h"
  2. int tree_count(char[323][31], int, int);
  3. int main() {
  4. char lines[323][31];
  5. int i = 0;
  6. while (scanf("%s", lines[i++]) == 1)
  7. ;
  8. long product = 1;
  9. product *= tree_count(lines, 3, 1);
  10. printf("Answer 1: %ld\n", product);
  11. product *= tree_count(lines, 1, 1);
  12. product *= tree_count(lines, 5, 1);
  13. product *= tree_count(lines, 7, 1);
  14. product *= tree_count(lines, 1, 2);
  15. printf("Answer 2: %ld\n", product);
  16. }
  17. int tree_count(char lines[323][31], int x_inc, int y_inc) {
  18. int x = 0, y = 0;
  19. int trees = 0;
  20. while (y < 323) {
  21. if (lines[y][x] == '#')
  22. trees++;
  23. y += y_inc; x += x_inc;
  24. x %= 31;
  25. }
  26. return trees;
  27. }