-
Notifications
You must be signed in to change notification settings - Fork 14
/
10100.cpp
100 lines (96 loc) · 2.86 KB
/
10100.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
using namespace std;
int LCSLength(vector<string> X, vector<string> Y){
int m = X.size();
int n = Y.size();
int c[m+1][n+1], i, j;
for(i=0; i<=m; i++)
c[i][0] = 0;
for(j=0; j<=n; j++)
c[0][j] = 0;
for(i=1; i<=m; i++)
for(j=1; j<=n; j++){
if(X[i-1] == Y[j-1])
c[i][j] = c[i-1][j-1] + 1;
else if(c[i-1][j] >= c[i][j-1])
c[i][j] = c[i-1][j];
else
c[i][j] = c[i][j-1];
}
return c[m][n];
}
int main(){
int i, j, t=1;
string strA, strB;
while(getline(cin, strA, '\n')){
getline(cin, strB, '\n');
vector < string > arrA;
vector < string > arrB;
int lenA=strA.length(), lenB=strB.length();
string temp="";
for(i=0; i<lenA; i++){
if(isalpha(strA[i]))
temp += strA[i];
else if(temp != ""){
arrA.push_back(temp);
temp = "";
}
}
if( isalpha(strA[lenA-1]) && temp!="" )
arrA.push_back(temp);
temp="";
for(i=0; i<lenB; i++){
if(isalpha(strB[i]))
temp += strB[i];
else if(temp != ""){
arrB.push_back(temp);
temp = "";
}
}
if( isalpha(strB[lenB-1]) && temp!="" ){
arrB.push_back(temp);
temp = "";
}
int lcsL = LCSLength(arrA, arrB);
/*
for(i=0; i<arrA.size(); i++)
cout<<arrA[i]<<" ";
cout<<endl;
for(i=0; i<arrB.size(); i++)
cout<<arrB[i]<<" ";
cout<<endl;
*/
if(lenA==0 || lenB==0){
printf("%2d. Blank!\n", t++);
continue;
}
printf("%2d. Length of longest match: %d\n", t++, lcsL);
}
}