#K13856. Swap First and Last Integers
Swap First and Last Integers
Swap First and Last Integers
You are given a string of integers separated by spaces. The task is to swap the first and last integers of the string. If the string contains fewer than two integers, simply return the string unchanged.
For example, if the input is "1 2 3 4 5", after swapping the first and the last numbers, the output will be "5 2 3 4 1".
The problem requires you to read the entire input from standard input (stdin) and print the result to standard output (stdout). Use appropriate methods to handle input and output per your language of choice.
Note: The swapping operation is defined only when there are at least two integers. Otherwise, the original string is returned without modifications.
inputFormat
The input consists of a single line containing a string of integers separated by spaces. The input is provided via standard input (stdin).
Example: 1 2 3 4 5
outputFormat
Output a single line which is the resultant string after swapping the first and last integers if applicable. The result should be printed to standard output (stdout).
Example: 5 2 3 4 1
1 2 3 4 5
5 2 3 4 1