Advertisement
tosip

Untitled

Jun 3rd, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include "input.h"
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int countTrees(int movX, int movY)
  7. {
  8.     const int numberOfRows = maps.size();
  9.     const int numberOfColumns = maps[0].length();
  10.     int x = 0, y = 0;
  11.     int treeCount = 0;
  12.  
  13.     while (y < maps.size())
  14.     {
  15.         const int readX = x % numberOfColumns;
  16.         char character = maps[y][readX];
  17.  
  18.         if (character == '#')
  19.         {
  20.             treeCount++;
  21.         }
  22.         x += movX;
  23.         y += movY;
  24.     }
  25.     cout << "treeCount: " << treeCount << endl;
  26.     return treeCount;
  27. }
  28.  
  29. int main()
  30. {
  31.     const int movX = 3, movY = 1;
  32.     long productOfTrees = 1;
  33.     int n1 = countTrees(1, 1); //79
  34.     int n2 = countTrees(3, 1); //216
  35.     int n3 = countTrees(5, 1); //91
  36.     int n4 = countTrees(7, 1); //96
  37.     int n5 = countTrees(1, 2); //45
  38.  
  39.     productOfTrees = n1 * n2 * n3 * n4 * n5;
  40.     //productOfTrees = (countTrees(1, 1) * countTrees(3, 1) * countTrees(5, 1) * countTrees(7, 1) * countTrees(1, 2));
  41.     cout << productOfTrees;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement