-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCTDL061.cpp
More file actions
38 lines (38 loc) · 764 Bytes
/
SCTDL061.cpp
File metadata and controls
38 lines (38 loc) · 764 Bytes
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
/**
* @file SCTDL061.cpp
* @author long (you@domain.com)
* @brief The longest common substring
* @version 0.1
* @date 2023-06-12
*
* @copyright Copyright (c) 2023
*
*/
#include <bits/stdc++.h>
using namespace std;
int LCS(string s1, string s2)
{
int F[s1.size() + 1][s2.size() + 1] = {};
for (int i = 0; i < s1.size(); i++)
{
for (int j = 0; j < s2.size(); j++)
{
if (s1[i] == s2[j])
F[i + 1][j + 1] = F[i][j] + 1;
else
F[i + 1][j + 1] = max(F[i][j + 1], F[i + 1][j]);
}
}
return F[s1.size()][s2.size()];
}
int main()
{
int t;
cin >> t;
while (t--)
{
string a, b;
cin >> a >> b;
cout << LCS(a, b) << endl;
}
}