TopCoder problem "MagicSpell" used in SRM 424 (Division II Level One)



Problem Statement

    You are given a String spell containing an ancient magic spell. The spell is encrypted, but the cypher is quite simple. To decrypt the spell, you need to find all occurrences of the letters 'A' and 'Z', and then reverse their order. For example, if the encrypted spell is "AABZCADZA", you would first find all the 'A's and 'Z's: "AA_Z_A_ZA". You would then reverse their order: "AZ_A_Z_AA". The final decrypted spell is "AZBACZDAA". Return the decrypted version of the given spell.
 

Definition

    
Class:MagicSpell
Method:fixTheSpell
Parameters:String
Returns:String
Method signature:String fixTheSpell(String spell)
(be sure your method is public)
    
 

Constraints

-spell will contain between 1 and 50 uppercase letters ('A'-'Z'), inclusive.

 

Examples

0)
    
"AZ"
Returns: "ZA"
This spell contains only letters 'A' and 'Z', so we just need to reverse it.
1)
    
"ABACADA"
Returns: "ABACADA"
This spell remains the same after decryption.
2)
    
"AABZCADZA"
Returns: "AZBACZDAA"
The example from the problem statement.
3)
    
"AZBASGHNAZAHBNVZZGGGAGGZAZ"
Returns: "ZABZSGHNAZZHBNVAZGGGAGGAZA"

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=10176

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13515&pm=10176

Writer:

Gluk

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Simple Search, Iteration