- #include<stdio.h>
- #include<string.h>
- int max(int a, int b) {
- return (a > b) ? a : b;
- }
- int lcs(char *str1, char *str2, int len1, int len2) {
- int lcs[len1+1][len2+1];
- int i, j;
- for (i = 0; i <= len1; i++) {
- for (j = 0; j <= len2; j++) {
- if (i == 0 || j == 0) {
- lcs[i][j] = 0;
- } else if (str1[i-1] == str2[j-1]) {
- lcs[i][j] = lcs[i-1][j-1] + 1;
- } else {
- lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
- }
- }
- }
- return lcs[len1][len2];
- }
- int main() {
- char str1[] = "VITCHENNAI";
- char str2[] = "VITVELLORE";
- int len1 = strlen(str1);
- int len2 = strlen(str2);
- int result = lcs(str1, str2, len1, len2);
- printf("%d\n", result);
- return 0;
- }
[text] q2
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: