Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Author : Saurav Kalsoor
- // Robot - JAVA
- import java.util.*;
- public class Test {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- int n = sc.nextInt();
- int x = sc.nextInt();
- int y = sc.nextInt();
- ArrayList<Integer> arr = new ArrayList<>();
- for(int i = 0;i < n; i++){
- arr.add(sc.nextInt());
- }
- robot(arr, x, y);
- }
- public static void robot(ArrayList<Integer> moves, int x, int y) {
- HashSet<String> set = new HashSet<>();
- set.add("0 0");
- int x_dir = 0, y_dir = 0, x_val = 0, y_val = 0;
- for(int i = 0;i < moves.size(); i++){
- switch(moves.get(i)){
- case 0:
- x_dir = 0;
- y_dir = 1;
- break;
- case 2:
- x_dir = 0;
- y_dir = -1;
- break;
- case 1:
- x_dir = 1;
- y_dir = 0;
- break;
- case 3:
- x_dir = -1;
- y_dir = 0;
- break;
- }
- x_val += x_dir;
- y_val += y_dir;
- if(set.contains(x_val + " " + y_val)){
- i--;
- }else{
- set.add(x_val + " " + y_val);
- }
- }
- System.out.println((x_val + x) + " " + (y_val + y));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement