3692. 最长连续公共子序列 - AcWing题库
题没啥好说的思路简单,打卡++
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string s1,s2;
int res = 0,s[1001],m[1001],maxn = 0;
cin >> s1 >> s2;
for (int i = 0; i < s1.length(); i ++ )
{
res = 0;
for(int j = 0;j < s2.length(); j ++)
{
if(res && s1[i] != s2[j]) {i -= res ;res = 0;j--;continue;}
if(s1[i] == s2[j])
{
res ++;s[res] = i;m[res] = i;i ++;
maxn = max(maxn,res);
s[res] = min(s[res],s[1]);
//cout <<s[res]<<" "<<m[res]<<" " <<res <<endl;
}
}
i -= res ;
}
cout << maxn <<endl;//<<" "<<s[maxn]<<" "<<m[maxn]
for (int i = s[maxn]; i <= m[maxn] ; i ++ )
cout << s1[i];
return 0;
}