暴力搜索法事件复杂度O(n^3)空间复杂度o(1)

#include <algorithm>
#include <vector>


using namespace std;

int main() {
    string str1,str2;
    
    while(cin>>str1>>str2){
        int m =str1.size();
        int n =str2.size();
        int tempi,tempj,maxlen=-1,len=0;
        
        for(int i =0;i<m;i++){
            
            for(int j = 0;j<n;j++){
                tempi =i;
                tempj =j;
                while(str1[tempi]==str2[tempj]&&tempi<m&&tempj<n){
                    len++;
                    tempi++;
                    tempj++;
                }
                if(len>maxlen)maxlen=len;
                len=0;//重新记长度
                
            }
        }
        
        cout<<maxlen<<endl;
    }
}