You are viewing a single comment's thread. Return to all comments →

What's the point of embedding the LCS problem in this dynamic-cast mystery problem?

Exactly my thought, it's two problems in one. I came for inheritance but I found the most complex part was the LCS.

here is solution of problem Magic Spells in c++ programming https://solution.programmingoneonone.com/2020/06/hackerrank-magic-spells-solution-in-c-plus-plus.html

Exactly. LCS is the only algorithm to implement here, it has nothing to do with C++ language knowledge. This exercise should be broken into 2 parts.

If anyone is wondering about a way to solve this problem without using Dynamic Cast in C++.

void counterspell(Spell *spell) { if(typeid(*spell) == typeid(Fireball)) { ((Fireball*)spell)->revealFirepower(); } else if(typeid(*spell) == typeid(Frostbite)) { ((Frostbite*)spell)->revealFrostpower(); } else if(typeid(*spell) == typeid(Thunderstorm)) { ((Thunderstorm*)spell)->revealThunderpower(); } else if(typeid(*spell) == typeid(Waterbolt)) { ((Waterbolt*)spell)->revealWaterpower(); } else { string spellName = spell->revealScrollName(); string spellJournal = SpellJournal::journal; // LCS Algorithm string &a = spellName, &b = spellJournal; vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1)); for(int i = 1; i <= a.size(); i++) { for(int j = 1; j <= b.size(); j++) { if(a[i - 1] == b[j - 1]) dp[i][j] = 1 + dp[i - 1][j - 1]; else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } cout << dp[a.size()][b.size()] << endl; } }

exactly my thought , why would anyone want to use dynamic_cast in this question ?

## Magic Spells

You are viewing a single comment's thread. Return to all comments →

What's the point of embedding the LCS problem in this dynamic-cast mystery problem?

Exactly my thought, it's two problems in one. I came for inheritance but I found the most complex part was the LCS.

here is solution of problem

Magic Spellsin c++ programming https://solution.programmingoneonone.com/2020/06/hackerrank-magic-spells-solution-in-c-plus-plus.htmlExactly. LCS is the only algorithm to implement here, it has nothing to do with C++ language knowledge. This exercise should be broken into 2 parts.

Exactly. LCS is the only algorithm to implement here, it has nothing to do with C++ language knowledge. This exercise should be broken into 2 parts.

If anyone is wondering about a way to solve this problem without using Dynamic Cast in C++.

exactly my thought , why would anyone want to use dynamic_cast in this question ?