#K10716. Reverse String if Even Length
Reverse String if Even Length
Reverse String if Even Length
Given a non-empty string s
, write a program that outputs its reverse if the length of s
is even; otherwise, output the original string. Formally, if |s| \mod 2 = 0
, output \(s^R\) (i.e. the reverse of s
), otherwise output s
unchanged.
For example:
- If
s = "abcd"
(length 4), then output"dcba"
. - If
s = "abc"
(length 3), then output"abc"
.
The input is provided from standard input and the result must be printed to standard output.
inputFormat
The input consists of a single line containing a string s
. The string may be empty. Read the input from standard input (stdin).
outputFormat
Output a single line to standard output (stdout): if the length of s
is even, output the reverse of s
; otherwise, output s
as it is.
abcd
dcba