P1563 玩具謎題:https://www.luogu.com.cn/problem/P1563
import java.util.*;
class Node{
String name = "";
int direction = 0;
Node(int direction, String name){
this.name = name;
this.direction = direction;
}
}
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();//小人
int m = scan.nextInt();//指令條數
Node[] node = new Node[n];
for (int i = 0; i < n; i ++){
node[i] = new Node(scan.nextInt(), scan.next());
}
int step = 0;
for (int i = 0; i < m; i ++){
int ans = scan.nextInt();
int num = scan.nextInt();
if ((ans == 0 && node[step].direction == 0) || (ans == 1 && node[step].direction == 1))
step = (step + n - num) % n;
else if ((ans == 0 && node[step].direction == 1) || (ans == 1 && node[step].direction == 0))
step = (step + num + n) % n;
}
System.out.print(node[step].name);
}
}