-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrightleft.java
More file actions
62 lines (57 loc) · 1.83 KB
/
rightleft.java
File metadata and controls
62 lines (57 loc) · 1.83 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
59
60
61
62
package Ishank;
import java.util.Scanner;
public class rightleft {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the length of the rows");
int r=sc.nextInt();
System.out.println("Enter the length of the columns");
int c= sc.nextInt();
String s="", q=sc.nextLine();
char[][] arr=new char[r][c];
for (int i = 0; i < r; i++) {
s=sc.nextLine();
for (int j = 0; j < c; j++) {
arr[i][j]=s.charAt(j);
}
}
boolean w=huihui(arr);
if(w)
System.out.println("VICTORY!!");
else
System.out.println("Bhakk saale");
}
static boolean huihui(char[][] arr){
if(arr[arr.length-1][arr[0].length-1]!='R')
return false;
if(arr[0][0]=='L' || arr[0][0]=='U')
return false;
int row=0, col=0;
int[][] arr2 =new int[arr.length][arr[0].length];
while (row >= 0 && row < arr.length && col >= 0 && col < arr[0].length) {
if(row==arr.length-1 && col==arr[0].length-1)
return true;
if(arr[row][col]=='X')
break;
switch(arr[row][col]){
case 'R':
arr[row][col]='X';
col++;
break;
case 'L':
arr[row][col]='X';
col--;
break;
case 'U':
arr[row][col]='X';
row--;
break;
case 'D':
arr[row][col]='X';
row++;
break;
}
}
return false;
}
}