-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution1
46 lines (41 loc) · 1.05 KB
/
Solution1
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
import java.util.*;
public class Hello {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
int c = sc.nextInt();
int[][] trees = new int[r][c];
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
trees[i][j]=sc.nextInt();
String shadow = sc.next();
int counter = 0;
for(int i =0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(shadow.equals("L"))
{
if(j!=c-1&&trees[i][j]==1&&trees[i][j+1]==0)
counter++;
}
else if(shadow.equals("R"))
{
if(j!=0&&trees[i][j]==1&&trees[i][j-1]==0)
counter++;
}
else if(shadow.equals("F"))
{
if(i!=0&&trees[i][j]==1&&trees[i-1][j]==0)
counter++;
}
else if(shadow.equals("B"))
{
if(i!=r-1&&trees[i][j]==1&&trees[i+1][j]==0)
counter++;
}
}
}
System.out.println(counter);
}
}