输入样例:
6 2
1 2 3 4 5 6
输出样例:
5 6 1 2 3 4
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
main();
}
public static void main() throws Exception {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int step = getStep(bufferedReader);
String[] targetString = bufferedReader.readLine().split(" ");
reverse(targetString, 0, targetString.length - 1);
reverse(targetString, 0, step - 1);
reverse(targetString, step, targetString.length - 1);
for (int i = 0 ; i < targetString.length - 1 ; i ++)
System.out.print(targetString[i] + " ");
System.out.print(targetString[targetString.length - 1]);
}
public static void reverse(String[] target, int start, int end) {
String temp = "";
for ( ; start < end ; start ++, end -- ) {
temp = target[start];
target[start] = target[end];
target[end] = temp;
}
}
public static int getStep(BufferedReader bufferedReader) throws Exception {
String line = bufferedReader.readLine();
String[] s = line.split(" ");
return Integer.parseInt(s[1]) % Integer.parseInt(s[0]);
}
}