Connection Status:
Competition Arena > MagicSpell
SRM 424 · 2008-11-05 · by Gluk · Simple Search, Iteration
Class Name: MagicSpell
Return Type: String
Method Name: fixTheSpell
Arg Types: (string)
Problem Statement

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.

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"
4)
"ZZZAZZFAZAZBANZZZFZAZZZPZAAASZZAZZZ"
Returns: "ZZZAZZFAAAZBZNZZAFZZZZAPZAZASZZAZZZ"

Submissions are judged against all 98 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class MagicSpell with a public method string fixTheSpell(string spell) · 98 test cases · 2 s / 256 MB per case

Submitting as anonymous