Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,m,i,j;
- char arr[100];
- char arr1[100];
- scanf("%s",arr);
- scanf("%s",arr1);
- n= strlen(arr);
- m= strlen(arr1);
- int array[n+1][m+1];
- for(i=0;i<=n;i++)
- {
- for(j=0;j<=m;j++)
- {
- if(i == 0 || j == 0)
- {
- array[i][j]=0;
- }
- else if(arr[i-1]==arr1[j-1])
- {
- array[i][j]=array[i-1][j-1]+1;
- }
- else
- {
- array[i][j]=max(array[i-1][j],array[i][j-1]);
- }
- }
- }
- printf("the longest common sequence is %d\n",array[n][m]);
- for(i=0;i<=n;i++)
- {
- for(j=0;j<=m;j++)
- {
- printf("%d ",array[i][j]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement