SHOW:
|
|
- or go back to the newest paste.
1 | // Author : Saurav Kalsoor | |
2 | - | // Robot - JAVA |
2 | + | // Robot - KOTLIN |
3 | ||
4 | - | import java.util.*; |
4 | + | import java.util.* |
5 | ||
6 | - | public class Test { |
6 | + | var sc: Scanner = Scanner(System.`in`) |
7 | - | static Scanner sc = new Scanner(System.in); |
7 | + | |
8 | - | public static void main(String[] args) { |
8 | + | fun main() { |
9 | - | int n = sc.nextInt(); |
9 | + | val n: Int = sc.nextInt() |
10 | - | int x = sc.nextInt(); |
10 | + | val x: Int = sc.nextInt() |
11 | - | int y = sc.nextInt(); |
11 | + | val y: Int = sc.nextInt() |
12 | val arr = ArrayList<Int>() | |
13 | - | ArrayList<Integer> arr = new ArrayList<>(); |
13 | + | for (i in 0 until n) { |
14 | - | for(int i = 0;i < n; i++){ |
14 | + | arr.add(sc.nextInt()) |
15 | - | arr.add(sc.nextInt()); |
15 | + | |
16 | - | } |
16 | + | robot(arr, x, y) |
17 | - | robot(arr, x, y); |
17 | + | |
18 | ||
19 | fun robot(moves: ArrayList<Int>, x: Int, y: Int) { | |
20 | - | public static void robot(ArrayList<Integer> moves, int x, int y) { |
20 | + | val set = HashSet<String>() |
21 | - | HashSet<String> set = new HashSet<>(); |
21 | + | set.add("0 0") |
22 | - | set.add("0 0"); |
22 | + | var x_dir = 0 |
23 | var y_dir = 0 | |
24 | - | int x_dir = 0, y_dir = 0, x_val = 0, y_val = 0; |
24 | + | var x_val = 0 |
25 | - | for(int i = 0;i < moves.size(); i++){ |
25 | + | var y_val = 0 |
26 | - | switch(moves.get(i)){ |
26 | + | var i = 0 |
27 | - | case 0: |
27 | + | while (i < moves.size) { |
28 | - | x_dir = 0; |
28 | + | when (moves[i]) { |
29 | - | y_dir = 1; |
29 | + | 0 -> { |
30 | - | break; |
30 | + | x_dir = 0 |
31 | - | case 2: |
31 | + | y_dir = 1 |
32 | - | x_dir = 0; |
32 | + | |
33 | - | y_dir = -1; |
33 | + | 2 -> { |
34 | - | break; |
34 | + | x_dir = 0 |
35 | - | case 1: |
35 | + | y_dir = -1 |
36 | - | x_dir = 1; |
36 | + | |
37 | - | y_dir = 0; |
37 | + | 1 -> { |
38 | - | break; |
38 | + | x_dir = 1 |
39 | - | case 3: |
39 | + | y_dir = 0 |
40 | - | x_dir = -1; |
40 | + | |
41 | - | y_dir = 0; |
41 | + | 3 -> { |
42 | - | break; |
42 | + | x_dir = -1 |
43 | y_dir = 0 | |
44 | - | x_val += x_dir; |
44 | + | |
45 | - | y_val += y_dir; |
45 | + | |
46 | - | if(set.contains(x_val + " " + y_val)){ |
46 | + | x_val += x_dir |
47 | - | i--; |
47 | + | y_val += y_dir |
48 | - | }else{ |
48 | + | if (set.contains("$x_val $y_val")) { |
49 | - | set.add(x_val + " " + y_val); |
49 | + | i-- |
50 | } else { | |
51 | set.add("$x_val $y_val") | |
52 | - | |
52 | + | |
53 | - | System.out.println((x_val + x) + " " + (y_val + y)); |
53 | + | i++ |
54 | } | |
55 | - | |
55 | + | println((x_val + x).toString() + " " + (y_val + y)) |
56 | } | |
57 | ||
58 |