ShortPalindromes
SRM 165 · 2003-09-23 · by vorthys
Problem Statement
A palindrome is a
Constraints
- base contains between 1 and 25 characters, inclusive.
- Every character in base is an uppercase letter ('A'-'Z').
"RACE" Returns: "ECARACE"
To make "RACE" into a palindrome, we must add at least three letters. However, there are eight ways to do this by adding exactly three letters: "ECARACE" "ECRARCE" "ERACARE" "ERCACRE" "RACECAR" "RAECEAR" "REACAER" "RECACER" Of these alternatives, "ECARACE" is the lexicographically earliest.
"TOPCODER" Returns: "REDTOCPCOTDER"
"Q" Returns: "Q"
"MADAMIMADAM" Returns: "MADAMIMADAM"
"ALRCAGOEUAOEURGCOEUOOIGFA" Returns: "AFLRCAGIOEOUAEOCEGRURGECOEAUOEOIGACRLFA"
Submissions are judged against all 54 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ShortPalindromes with a public method string shortest(string base) · 54 test cases · 2 s / 256 MB per case