#28. 交换数组首尾元素
交换数组首尾元素
Swap First and Last Elements
Background
Dawei is organizing some number sequences, and he wants to perform a simple operation on each sequence.
Problem Description
Given an array of integers, swap the first and last elements in the array. Return the modified array. The array length will be at least .
Input Format
Input is given from standard input in the following format.
A single line containing several integers, representing the elements of the array. These integers are separated by spaces.
Output Format
Output to standard output in the following format.
A single line containing the elements of the modified array, formatted as
[x, y, z, ...]with elements separated by commas and spaces.
Sample
1 2 3 4
[4, 2, 3, 1]
1 2 3
[3, 2, 1]
8 6 7 9 5
[5, 6, 7, 9, 8]
Constraints
- The length of the array satisfies .
- Each element in the array is an integer, and its absolute value does not exceed .
- Time limit: second, Memory limit: KiB.