-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForest.java
More file actions
58 lines (57 loc) · 1.33 KB
/
Forest.java
File metadata and controls
58 lines (57 loc) · 1.33 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class Forest {
public static void main(String[] args) throws FileNotFoundException
{
Scanner fin = new Scanner(new File("forest.dat"));
String[] temp = fin.nextLine().split(" ");
int N = Integer.parseInt(temp[0]);
int[] heights = new int[N];
int max = 0;
for (int i = 1; i <= N; i++)
{
heights[i-1] = Integer.parseInt(temp[i]);
max = Math.max(heights[i-1], max);
}
if (max == 0)
return;
int[][] isTree = new int[(max+1)*2 + 1][N];
int boardY = isTree.length;
for (int i = 0; i < N; i++)
{
if (heights[i] == 0)
continue;
isTree[boardY-1][i] = 3;
isTree[boardY-2][i] = 3;
for (int j = 0; j < heights[i]; j++)
{
isTree[boardY-3 - (j*2)][i] = 2;
isTree[boardY-3 - (j*2 + 1)][i] = 1;
}
isTree[boardY-3 - (heights[i]*2)][i] = 4;
}
String four = " /\\ ";
String one = " / \\ ";
String two = "/_ _\\ ";
String three = " || ";
String zero = " ";
for (int[] row: isTree)
{
for (int cell:row)
{
if (cell == 0)
System.out.print(zero);
if (cell == 1)
System.out.print(one);
if (cell == 2)
System.out.print(two);
if (cell == 3)
System.out.print(three);
if (cell == 4)
System.out.print(four);
}
System.out.println();
}
}
}