Haggard1 0 Newbie Poster

Hi,

I am looking for a solution the longest common substring problem. I have the code but in C++. Can someone help me to convert the code in Multi-pascal because I need a code which is for parallel processing. Thanks.

#include <iostream>
#include <string>

using namespace std;
int main () {
        
        while(1) {
                
                string first, second, lcsub, max;
                
                cout << "Enter two words" << endl;
                cin >> first >> second;
                if(cin.eof()) {
                        return 0;
                }
                for (int i=0; i < first.length(); i++){
                                for (int j=0; j < second.length(); j++){
                                        for (int k=1; k <= first.length() && k <= second.length(); k++){
                                                if (first.substr(i,k) == second.substr(j,k)){
                                                        lcsub = first.substr(i,k);
                                                }
                                                else{
                                                        if (lcsub.length() > max.length())
                                                                max=lcsub;
                                                        lcsub="";
                                                }
                                        }
                                                if (lcsub.length() > max.length())
                                                                max=lcsub;
                                                lcsub="";
                                }
                }
                cout << "Longest Common Substring: " << max << endl << endl;
        }
        return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.