-
Notifications
You must be signed in to change notification settings - Fork 19
/
boundingrobots.java
70 lines (59 loc) · 1.09 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
import java.util.Scanner;
public class boundingrobots {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (true)
{
int ThinkX = 0;
int ThinkY = 0;
int x = 0;
int y = 0;
int w = scan.nextInt() - 1;
int l = scan.nextInt() - 1;
if (w + 1 == 0 && l + 1 == 0)
break;
int moves = scan.nextInt();
for (int i = 0; i < moves; i++)
{
String direction = scan.next();
int distance = scan.nextInt();
if (direction.equals("u"))
{
if (y + distance > l)
y = l;
else
y += distance;
ThinkY += distance;
}
else if (direction.equals("d"))
{
if (y - distance < 0)
y = 0;
else
y -= distance;
ThinkY -= distance;
}
else if (direction.equals("r"))
{
if (x + distance > w)
x = w;
else
x += distance;
ThinkX += distance;
}
else
{
if (x - distance < 0)
x = 0;
else
x -= distance;
ThinkX -= distance;
}
}
System.out.println("Robot thinks " + ThinkX + " " + ThinkY);
System.out.println("Actually at " + x + " " + y);
System.out.println();
}
scan.close();
}
}