试题 算法提高 桌上的书java
初学
笨方法
看看就行
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
int a = n;
String[] dou = new String[m];
String[] book1 = new String[n + m];
for(int i = 0;i < n;i++) {
book1[n - i - 1] = sc.next();
}
for(int i = 0;i < m;i++) {
dou[i] = sc.next();
}
for(int i = 0;i < m;i++) {
String name = dou[i];
char[] name1 = name.toCharArray();
if (name1[0] == 'A') {
book1[a] = dou[i].substring(4, name1.length - 1);
a++;
} else if (name1[0] == 'R') {
if(a >= k) {
for (int j = 0; j < k / 2; j++) {
String temp = book1[a - 1 - j];
book1[a - 1 - j] = book1[a - k + j];
book1[a - k + j] = temp;
}
}else{
for (int j = 0; j < a / 2; j++) {
String temp = book1[a - 1 - j];
book1[a - 1 - j] = book1[j];
book1[j] = temp;
}
}
}
}
for(int i = 0;i < book1.length;i++) {
if(book1[book1.length - i - 1] == null) {
continue;
}
System.out.println(book1[book1.length - i - 1]);
}
}
}