Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cctype>
- #include <stack>
- #include <queue>
- #include <list>
- #include <vector>
- #include <map>
- #include <set>
- #include <sstream>
- #include <limits.h>
- #include <stdlib.h>
- #include <cmath>
- #define LL unsigned long long
- using namespace std;
- int lcs[1010][1010];
- int main() {
- int cont=1;char s1[1010];char s2[1010];
- while(gets(s1)){
- gets(s2);
- if(s1[0] == '\0' || s2[0] == '\0') {
- printf("%2d. Blank!\n",cont++);continue;
- }
- string str1[1010], str2[1010];
- int count1 = 0 , count2 = 0;
- bool isIn = false;
- for(int i = 0 ; i < strlen(s1) ; i++)
- {
- char c = s1[i];
- if(isalpha(c) || isdigit(c))
- {
- if(!isIn)
- {
- count1++;
- str1[count1] += c;
- isIn = true;
- }
- else str1[count1] += c;
- }
- else isIn = false;
- }
- isIn = false;
- for(int i = 0 ; i < strlen(s2) ; i++)
- {
- char c = s2[i];
- if(isalpha(c) || isdigit(c))
- {
- if(!isIn)
- {
- count2++;
- str2[count2] += c;
- isIn = true;
- }
- else str2[count2] += c;
- }
- else isIn = false;
- }
- memset(lcs, 0, sizeof(lcs));
- for (int i=1;i<=count1;i++){
- for(int j=1;j<=count2;j++){
- if(str1[i]==str2[j]){
- lcs[i][j]=1+lcs[i-1][j-1];
- }else
- lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
- }
- }
- printf("%2d. Length of longest match: %d\n", cont++, lcs[count1][count2]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement