top1编程
← 返回题目
题解

【基础】重叠的字符串

1 条题解

  • 0
    @ 2026-7-29 0:18:56
    #include<bits/stdc++.h>
    using namespace std;
    string n,m; 
    int main(){
       cin>>n>>m;
       long long o=0; 
        for(int l=0; l<n.size(); l++){
        	for(int k=l; k<n.size(); k++){
        		for(int j=0; j<m.size(); j++){
        			if(m.substr(j,k-l+1)==n.substr(l,k-l+1)){
        				if(o<k-l+1){
        					o=k-l+1;
    					}
    				}
    			}
    		}
    	}
    	cout<<o;
    }
    
    • 1