-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.cpp
More file actions
33 lines (33 loc) · 734 Bytes
/
task1.cpp
File metadata and controls
33 lines (33 loc) · 734 Bytes
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
#include<iostream>
using namespace std;
int bintree[10000];
int n = 1000;
int dfs(int cur)
{
int lson = cur * 2 + 1, rson = cur * 2 + 2;
int lsonl = lson * 2 + 1, lsonr = lson * 2 + 2;
int rsonl = rson * 2 + 1, rsonr = rson * 2 + 2;//grandsons
if (bintree[cur] % 5 == 0)
{
if (lsonl < n)
cout<<bintree[lsonl]<<" ";
if (lsonr < n)
cout<<bintree[lsonr]<<" ";
if (rsonl < n)
cout<<bintree[rsonl]<<" ";
if (rsonr < n)
cout<<bintree[rsonr]<<" ";
}
if (lson < n)
dfs(lson);
if (rson < n)
dfs(rson);
return 0;
}
int main()
{
for (int i = 0; i < n; i++)
bintree[i] = i;
dfs(0);
return 0;
}