-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutopianTree.cpp
More file actions
42 lines (31 loc) · 775 Bytes
/
utopianTree.cpp
File metadata and controls
42 lines (31 loc) · 775 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
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
// Complete the utopianTree function below.
int utopianTree(int n) {
int height = 0, lifeCycle = 0;
while (lifeCycle <= n) {
if ((lifeCycle%2) == 0) {
height = height + 1;
} else if ((lifeCycle%2) != 0) {
height = height * 2;
}
lifeCycle++;
}
return height;
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int t;
cin >> t;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int t_itr = 0; t_itr < t; t_itr++) {
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int result = utopianTree(n);
fout << result << "\n";
}
fout.close();
return 0;
}