只看我的做法就够了
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<vector> #include<queue> #include<stack> using namespace std; const int maxn = 1005; int n,m,ans; char a[maxn],b[maxn]; int main(){ cin>>a>>b; n = strlen(a); m = strlen(b); int l,r,tmp; for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ tmp = 0; for(int k = 1;i + k -1 < n && j + k -1 < m;k++){ if(a[i+k-1] == '1' && b[j+k-1] == '1') tmp++; } if(ans < tmp) ans = tmp; } } cout<<ans; return 0; }