Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n,m,i,j;
  8.  
  9. char arr[100];
  10. char arr1[100];
  11. scanf("%s",arr);
  12. scanf("%s",arr1);
  13. n= strlen(arr);
  14. m= strlen(arr1);
  15. int array[n+1][m+1];
  16. for(i=0;i<=n;i++)
  17. {
  18. for(j=0;j<=m;j++)
  19. {
  20. if(i == 0 || j == 0)
  21. {
  22. array[i][j]=0;
  23. }
  24. else if(arr[i-1]==arr1[j-1])
  25. {
  26. array[i][j]=array[i-1][j-1]+1;
  27. }
  28. else
  29. {
  30. array[i][j]=max(array[i-1][j],array[i][j-1]);
  31. }
  32. }
  33. }
  34. printf("the longest common sequence is %d\n",array[n][m]);
  35. for(i=0;i<=n;i++)
  36. {
  37. for(j=0;j<=m;j++)
  38. {
  39. printf("%d ",array[i][j]);
  40. }
  41. printf("\n");
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement