-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
102 lines (79 loc) · 1.79 KB
/
solution.java
File metadata and controls
102 lines (79 loc) · 1.79 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
/* Head ends here */
static void displayPathtoPrincess(int n, String [] grid)
{
int size = n*n;
int ppos_i = 0;
int mpos_i = 0;
int ppos_j = 0;
int mpos_j = 0;
char [][]final;
target = new char[n][];
for(int i=0;i<n;i++)
target[i] = grid[i].toCharArray();
for(int i = 0; i < n; i++)
{
// System.out.println();
for(int j = 0; j<n; j++)
{
//System.out.print(target[i][j]);
if (final[i][j] == 'p')
{ppos_i = i; ppos_j = j;}
if (final[i][j] == 'm')
{mpos_i = i; mpos_j = j;}
}
}
/*ppos_i = ppos/n;
ppos_j = ppos%n;
mpos_i = mpos/n;
mpos_i = mpos%n;
*/
while(ppos_i != mpos_i)
{
/*System.out.print(ppos_i);
System.out.print(ppos_j);
System.out.println();
System.out.print(mpos_i);
System.out.print(mpos_j); */
if (mpos_i < ppos_i )
{
System.out.println("DOWN");
mpos_i = mpos_i + 1;
}
else
{
System.out.println("UP");
mpos_i= mpos_i - 1;
// System.out.println( mpos_j);
}
}
while(ppos_j != mpos_j)
{
if(mpos_j < ppos_j)
{ System.out.println("RIGHT");
mpos_j++;
}
else
{
System.out.println("LEFT");
mpos_j--;
}
}
}
/* Tail starts here */
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m;
m = in.nextInt();
String grid[] = new String[m];
for(int i = 0; i < m; i++) {
grid[i] = in.next();
}
displayPathtoPrincess(m,grid);
}
}