publicstaticvoidmain(String[] args) { Scannersc=newScanner(System.in); int N, M; N = sc.nextInt(); M = sc.nextInt(); //第一行输入 int[] arr = newint[N + 2]; for (inti=1; i <= N; i++) { arr[i] = i; //arr数组存储每个数字对应的位置 } Character key; Integer value; for (inti=0; i < M; i++) { key = sc.next().charAt(0); value = sc.nextInt(); //第二行输入 if (key.toString().equals("L")) {
Lexchange(arr, value, N); //左移 } else {
Rexchange(arr, value, N); //右移 } } int[] R = newint[N + 1]; for (inti=1; i <= N; i++) { R[arr[i]] = i; } for (inti=1; i <= N; i++) { System.out.print(R[i]+" "); }
}
publicstaticvoidLexchange(int[] arr, int x, int N) { intj=0; for (inti=1; i <= N; i++) { if (arr[i] < arr[x]) { arr[i]++; j++; } if (j == arr[x] - 1) { arr[x] = 1; return; } }
}
publicstaticvoidRexchange(int[] arr, int x, int N) { intj=0; for (inti=1; i <= N; i++) { if (arr[i] > arr[x]) { arr[i]--; j++; } if (j == N-arr[x]) { arr[x]=N; return; } }
publicstaticvoidmain(String[] args) { Scannersc=newScanner(System.in); int N, M; N = sc.nextInt(); M = sc.nextInt(); //第一行输入 int[][] arr = newint[N+1][2]; //arr二维数组存储数字与权值 for (inti=1; i <= N; i++) { arr[i][0]=arr[i][1]=i; //初始化arr二维数组 } Character key; Integer value; int L=0,R=N+1; //初始化左右权值 for (inti=0; i < M; i++) { key = sc.next().charAt(0); value = sc.nextInt(); if (key.toString().equals("L")) {