-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathboundingrobots.java
76 lines (63 loc) · 1.26 KB
/
boundingrobots.java
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
import java.util.Scanner;
public class boundingrobots {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while(scan.hasNext())
{
int c = scan.nextInt();
int r = scan.nextInt();
if(r == 0 && c == 0)
break;
int test = scan.nextInt();
scan.nextLine();
//fictional
int currx = 0;
int curry = 0;
//actual
int actx = 0;
int acty = 0;
while(test --> 0)
{
String dir = scan.next();
int mag = scan.nextInt();
scan.nextLine();
if(dir.equals("u"))
{
curry += mag;
if(acty + mag >= r)
acty = r-1;
else
acty += mag;
}
if(dir.equals("d"))
{
curry -= mag;
if(acty - mag < 0)
acty = 0;
else
acty -= mag;
}
if(dir.equals("r"))
{
currx += mag;
if(actx + mag >= c)
actx = c-1;
else
actx += mag;
}
if(dir.equals("l"))
{
currx -= mag;
if(actx - mag < 0)
actx = 0;
else
actx -= mag;
}
}
System.out.println("Robot thinks " + currx + " " + curry);
System.out.println("Actually at " + actx + " " + acty);
System.out.println();
}
scan.close();
}
}