Problem 1 - Hogwarts
Welcome, wizard. We have been waiting for you here, in Hogwarts. Get ready to learn a lot of new
potions and spells to fight The one who shall not be named. Your first class is Spellcasting.
First, you will receive a spell that needs to be deciphered. Next, you will be receiving commands split by
a single space until you get the "Abracadabra" command. There are 5 possible commands:
"Abjuration"
o Replace all letters with upper case and print the result.
"Necromancy"
o Replace all letters with lower case and print the result.
"Illusion {index} {letter}"
o Replace the letter at the index with the given one and print "Done!"
o If the index is invalid, print: "The spell was too weak."
"Divination {first substring} {second substring}"
o Replace the first substring (all matches) with the second and print the result.
o If the substring does not exist, skip the command.
"Alteration {substring}"
o Remove the substring from the string and print the result.
o If the substring does not exist, skip the command.
If the input command is not in the list, print "The spell did not work!".
Input / Constraints
On the 1st line, you are going to receive the string.
On the next lines, until you receive "Abracadabra", you will be receiving commands.
All commands are case-sensitive.
Output
Print the output of the commands in the format described above.
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us:
Examples
Input Output
A7ci0 Done!
Illusion 1 c Done!
Illusion 4 o ACCIO
Abjuration
Abracadabra
TR1GG3R tr1gg3r
Necromancy The spell was too weak.
Illusion 8 m The spell was too weak.
Illusion 9 n
Abracadabra
SwordMaster The spell did not work!
Target Target Target SWORDMASTER
Abjuration swordmaster
Necromancy sword
Alteration master
Abracadabra
JS Examples
Input Output
(["A7ci0", Done!
"Illusion 1 c", Done!
"Illusion 4 o", ACCIO
"Abjuration",
"Abracadabra"])
(["TR1GG3R", tr1gg3r
"Necromancy", The spell was too weak.
"Illusion 8 m", The spell was too weak.
"Illusion 9 n",
"Abracadabra"])
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us:
(["SwordMaster", The spell did not work!
"Target Target Target", SWORDMASTER
"Abjuration", swordmaster
"Necromancy", sword
"Alteration master",
"Abracadabra"])
© SoftUni – about.softuni.bg. Copyrighted document. Unauthorized copy, reproduction or use is not permitted.
Follow us: