TopcoderArchiveVisit Topcoder
SRM12 Jun 2002
SRM 97

MountainP

Problem statement, definition, constraints, and public examples.

Problem Statement

To make a Mountain Palindrome from a given String you must sort the String's characters in ascending order and then append the fewest number of characters required for it to be a palindrome. A palindrome is a string that is the same backwards as forwards. For example, "ABCCBA", "DEED", and "RADAR" are all palindromes.

Create a class MountainP that contains the method makeMP, which takes a String before and returns a String that is the generated Mountain Palindrome.

Definition

Class:
MountainP
Method:
makeMP
Parameters:
String
Returns:
String
Method signature:
String makeMP(String before)
(be sure your method is public)

Notes

  • Remember to append the FEWEST number of characters required to produce a palindrome.

Constraints

  • before will have between 1 and 25 characters, inclusive.
  • before will only contain capital letters ('A'-'Z').

Examples

  1. "BEFORESTRING"
    Returns: "BEEFGINORRSTSRRONIGFEEB"
    First we sort: "BEEFGINORRST" Next we append the fewest number of characters required to produce a palindrome.
  2. "AZZAZ"
    Returns: "AAZZZAA"
    First we sort: "AAZZZ" Next we append the fewest number of characters required to produce a palindrome.
  3. "PROGRAMMING"
    Returns: "AGGIMMNOPRRPONMMIGGA"
  4. "ABRACADABRA"
    Returns: "AAAAABBCDRRDCBBAAAAA"
  5. "CINDERELLA"
    Returns: "ACDEEILLNRNLLIEEDCA"
  6. "A"
    Returns: "A"
  7. "AB"
    Returns: "ABA"
Back to all problems