#13. 字符串首尾字符交换
字符串首尾字符交换
Swap First and Last Characters
Background
Congcong is currently learning about string manipulation. He encountered an interesting task that requires swapping the first and last characters of a given string.
Problem Description
Given a string, return a new string where the first and last characters have been exchanged.
Input Format
The input consists of a single line, containing a string.
s
Output Format
The output consists of a single line, containing the new string after swapping its first and last characters.
result_s
Sample
code
"eodc"
a
"a"
ab
"ba"
Sample Explanation
- Sample 1: The input string is "code". The first character is 'c', and the last character is 'e'. After swapping, the result is "eodc".
- Sample 2: The input string is "a". There is only one character, so the first and last characters are the same. After swapping, it remains "a".
- Sample 3: The input string is "ab". The first character is 'a', and the last character is 'b'. After swapping, the result is "ba".
Constraints
Time limit: 1s, Memory limit: 1024KiB for each test case.