提交时间:2023-12-16 08:37:12

运行 ID: 116128

#include<bits/stdc++.h> using namespace std; char s1[1001]; char s2[1001]; int maxlen[1001][1001]; int main() { cin>>s1>>s2; int len1=strlen(s1); int len2=strlen(s2); int i,j; for(i=0;i<=len1;i++) maxlen[i][0]=0; for(j=0;j<=len2;j++) maxlen[0][j]=0; for(i=1;i<=len1;i++) { for(j=1;j<=len2;j++) { if(s1[i-1]==s2[j-1]) maxlen[i][j]=maxlen[i-1][j-1]+1; else maxlen[i][j]=max(maxlen[i-1][j],maxlen[i][j-1]); } } if(maxlen[len1][len2]==min(len1,len2)) cout<<"true"; else cout<<"false"; }