public class Solution2 { //7 2 1 2 3 4 5 6 7 static int[] cards; @SuppressWarnings("all") public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int k = Integer.parseInt(s[1]); cards = new int[s.length - 2]; for (int i = 0; i < cards.length; i++) { cards[i] = Integer.parseInt(s[i + 2]); } for (int m = 0; m < 2; m++) { int[] temp = new int[cards.length]; int i = n % 2 == 0 ? n / 2 - 1 : n / 2; int j = cards.length - 1; int idx = cards.length - 1; if (m % 2 == 0) {//奇数 while (idx >= 0 && i >= 0 && j >= 0) { if (idx > 0){ temp[idx--] = cards[j--]; temp[idx--] = cards[i--]; } else if (idx == 0) temp[idx] = cards[i--]; } }else { while (idx >= 0 && i >= 0 && j >= 0) { if (idx > 0){ temp[idx--] = cards[i--]; temp[idx--] = cards[j--]; } else if (idx == 0) temp[idx] = cards[i--]; } } cards = temp; } for (int card : cards) { System.out.print(card + " "); } } }
全部评论
(0) 回帖