We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<iostream>#include<vector>#include<string>usingnamespacestd;classSpell{private:stringscrollName;public:Spell():scrollName(""){}Spell(stringname):scrollName(name){}virtual~Spell(){}stringrevealScrollName(){returnscrollName;}};classFireball:publicSpell{private:intpower;public:Fireball(intpower):power(power){}voidrevealFirepower(){cout<<"Fireball: "<<power<<endl;}};classFrostbite:publicSpell{private:intpower;public:Frostbite(intpower):power(power){}voidrevealFrostpower(){cout<<"Frostbite: "<<power<<endl;}};classThunderstorm:publicSpell{private:intpower;public:Thunderstorm(intpower):power(power){}voidrevealThunderpower(){cout<<"Thunderstorm: "<<power<<endl;}};classWaterbolt:publicSpell{private:intpower;public:Waterbolt(intpower):power(power){}voidrevealWaterpower(){cout<<"Waterbolt: "<<power<<endl;}};classSpellJournal{public:staticstringjournal;staticstringread(){returnjournal;}};stringSpellJournal::journal="";voidcounterspell(Spell*spell){if(dynamic_cast<Fireball*>(spell)){Fireball*f=(Fireball*)spell;f->revealFirepower();}elseif(dynamic_cast<Frostbite*>(spell)){Frostbite*f=(Frostbite*)spell;f->revealFrostpower();}elseif(dynamic_cast<Thunderstorm*>(spell)){Thunderstorm*f=(Thunderstorm*)spell;f->revealThunderpower();}elseif(dynamic_cast<Waterbolt*>(spell)){Waterbolt*f=(Waterbolt*)spell;f->revealWaterpower();}else{//cout<<"here"<<endl;strings2=spell->revealScrollName();strings1=SpellJournal::journal;vector<vector<int>>dp(s1.size()+1,vector<int>(s2.size()+1,0));for(inti=1;i<=s1.size();i++){for(intj=1;j<=s2.size();j++){if(s1[i-1]==s2[j-1]){dp[i][j]=dp[i-1][j-1]+1;}else{dp[i][j]=max(dp[i][j-1],dp[i-1][j]);}}}cout<<dp[s1.size()][s2.size()]<<endl;}/* Enter your code here */}classWizard{public:Spell*cast(){Spell*spell;strings;cin>>s;intpower;cin>>power;if(s=="fire"){spell=newFireball(power);}elseif(s=="frost"){spell=newFrostbite(power);}elseif(s=="water"){spell=newWaterbolt(power);}elseif(s=="thunder"){spell=newThunderstorm(power);}else{spell=newSpell(s);cin>>SpellJournal::journal;}returnspell;}};intmain(){intT;cin>>T;WizardArawn;while(T--){Spell*spell=Arawn.cast();counterspell(spell);}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Magic Spells
You are viewing a single comment's thread. Return to all comments →
Take my whiskey neat Solution