publicclassMain{ publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); //int[] arr = new int[n]; //map 记录每个元素所在的位置 int[] map = newint[n+1]; for (int i = 0; i int ai = scanner.nextInt(); map[ai] = i; } int x = scanner.nextInt(); int y = scanner.nextInt();
n = int(input()) arr = list(map(int, input().split())) x, y = map(int, input().split())
for i in range(n - 1): if (arr[i] == x and arr[i + 1] == y) or (arr[i] == y and arr[i + 1] == x): print("Yes") break else: print("No")
Java
import java.util.Scanner;
publicclassMain{ publicstaticvoidmain(String[] args){ Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] arr = newint[n]; for (int i = 0; i arr[i] = scanner.nextInt(); } int x = scanner.nextInt(); int y = scanner.nextInt();
for (int i = 0; i 1; i++) { if ((arr[i] == x && arr[i + 1] == y) || (arr[i] == y && arr[i + 1] == x)) { System.out.println("Yes"); return; } } System.out.println("No"); } }
C++
#include usingnamespacestd;
intmain(){ int n; cin >> n;
int arr[n]; for (int i = 0; i cin >> arr[i]; }
int x, y; cin >> x >> y;
for (int i = 0; i 1; i++) { if ((arr[i] == x && arr[i + 1] == y) || (arr[i] == y && arr[i + 1] == x)) { cout <"Yes" return0; } } cout <"No" return0; }