-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshortest_path.java
More file actions
42 lines (39 loc) · 939 Bytes
/
Copy pathshortest_path.java
File metadata and controls
42 lines (39 loc) · 939 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
public class shortest_path
{
public static int short_path(String path)
{
int x=0;
int y=0;
for(int i=0; i<path.length() ; i++)
{
char c = path.charAt(i);
if(c =='W')
{
--x;
}
else if(c == 'E')
{
++x;
}
else if(c =='N')
{
++y;
}
else
{
--y;
}
}
System.out.println("co ordinates" + "(" +x +"," +y +")");
int x2 = x*x;
int y2 = y*y;
int p = (int)Math.sqrt(x2 + y2);
return p;
}
public static void main(String[] args)
{
String path ;
path = "WNEENESENNN" ;
System.out.print("shortest path :-"+short_path(path));
}
}