#K82047. Generate Symmetrical String
Generate Symmetrical String
Generate Symmetrical String
Given an integer n (with the constraint $$1 \le n \le 100$$), generate a symmetrical alphanumeric string of length n. A symmetrical string (i.e. a palindrome) reads the same forwards and backwards. The generated string should use the sequence of lowercase letters (a
to z
) cyclically. Specifically, construct the first half of the string by taking the first floor(n/2) characters from the cyclic sequence, and then mirror them. For odd values of n, an extra middle character is inserted which is also chosen from the sequence.
If the input n is not within the valid range, output -1
.
inputFormat
The input consists of a single line containing an integer n.
outputFormat
Output the generated symmetrical string according to the rules described above. If n is outside the valid range, output -1
.
5
abcba