import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int n = in.nextInt(); // 构建链表 ListNode listNode = new ListNode(-1); // 头结点 ListNode first = listNode; for (int i = 0; i < n; i++) { int v = in.nextInt(); ListNode next = new ListNode(v); listNode.next = next; listNode = next; } int k = in.nextInt(); System.out.println(searchListNode(first, n -k + 1)); } } public static int searchListNode(ListNode first, int k) { int t = 0; // 正向查找 ListNode tn = first; for (int i = 0; i <= k; i++) { if (i == k) { t = tn.key; } else { tn = tn.next; } } return t; } } class ListNode { int key; ListNode next; ListNode(int key) { this.key = key; next = null; } }