Witam!
Mam problem z napisaniem programu podającego długość NWP trzech stringów. Byłbym wdzięczny za wszelkie rady:
#include <cstdio>
#include <string>
#include <string.h>
#include <iostream>
using namespace std;
int max(int a, int b, int c)
{
return max(max(a, b), c);
}
int findLCS (string S1, string S2, string S3 )
{
int LCS[100][100][100];
for(int i=1; i<=S1.size(); i++)
for(int j=1; j<=S2.size(); j++)
for(int k=1; k<=S3.size(); k++)
{
if (S1[i-1]==S2[j-1] && S2[j-1]==S3[k-1])
LCS[i][j][k]=LCS[i-1][j-1][k-1]+1;
else
LCS[i][j][k]=max(LCS[i-1][j][k], LCS[i][j-1][k], LCS[i][j][k-1]);
}
return LCS[S1.size()][S2.size()][S3.size()];
}
int main ()
{
int ltestow;
scanf("%d", <estow);
char tab[3][100];
while(ltestow--)
{
scanf(" %s %s %s ", tab[1], tab[2], tab[0]);
string S1(tab[1]), S2(tab[2]), S3(tab[0]);
printf("%d\n", findLCS(S1, S2, S3));
}
}
Dziękuję!