-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.cpp
43 lines (39 loc) · 809 Bytes
/
2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
int countTrees(std::vector<std::string> map, int dx, int dy)
{
int x = 0;
int y = 0;
int count = 0;
while(y < (int) map.size())
{
x = (x + dx) % map[0].size();
y += dy;
if (map[y][x] == '#')
{
count++;
}
}
return count;
}
int main()
{
std::vector<std::string> map;
std::string str;
while(std::cin)
{
std::getline(std::cin, str);
map.push_back(str);
}
std::vector<int> dx = {1, 3, 5, 7, 1};
std::vector<int> dy = {1, 1, 1, 1, 2};
unsigned long long count = 1;
for(int i = 0; (int) i < dx.size(); ++i)
{
count *= countTrees(map, dx[i], dy[i]);
}
printf("%lld", count);
return 0;
}