Magic Spells

  • + 0 comments
    if (Fireball* fireball = dynamic_cast<Fireball*>(spell)) {
            fireball->revealFirepower();
        }
        else if (Frostbite* frostbite = dynamic_cast<Frostbite*>(spell)) {
            frostbite->revealFrostpower();
        }
        else if (Thunderstorm* thunderstorm = dynamic_cast<Thunderstorm*>(spell)) {
            thunderstorm->revealThunderpower();
        }
        else if (Waterbolt* waterbolt = dynamic_cast<Waterbolt*>(spell)) {
            waterbolt->revealWaterpower();
        }
        else {
            string scrollName = spell->revealScrollName();
            string journal = SpellJournal::read();
            int n = scrollName.length();
            int m = journal.length();
    
            vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (scrollName[i - 1] == journal[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[n][m] << endl;
        }