Description
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
Sample Input
Sample Output
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int c[1000][1000];
int main()
{
char s1[1000],s2[1000];
int len1,len2;
while(scanf("%s%s",s1,s2)!=EOF)
{
len1=strlen(s1);
len2=strlen(s2);
for(int i=0;i<len1;i++)
c[i][0]=0;
for(int j=0;j<len2;j++)
c[0][j]=0;
for(int i=1;i<=len1;i++)
{
for(int j=1;j<=len2;j++)
{
if(s1[i-1]==s2[j-1])
c[i][j]=c[i-1][j-1]+1;
else
c[i][j]=max(c[i-1][j],c[i][j-1]);
}
}
printf("%d\n",c[len1][len2]);
}
return 0;
}