提交时间:2023-12-16 08:33:22
运行 ID: 116119
#include <iostream> #include <string.h> #include <algorithm> #define MAX 1000 using namespace std; char s1[MAX]; char s2[MAX]; int maxlen[MAX][MAX]; int main() { while(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"; } return 0; }