1 solutions

  • 0
    @ 2025-11-5 15:18:49

    C++ :

    #include <iostream>
    using namespace std;
    int main(){
    	//freopen("test6.in","r",stdin);
        string a,b;
        int la,lb,ai,bi,c,ans=0;
        cin>>a>>b;
        la=a.size();
        lb=b.size();
        for(int i=0;i<la;i++){
            for(int j=0;j<lb;j++){
                ai=i,bi=j,c=0;
                while(a[ai]==b[bi]&&c<min(la,lb)){
                    ai++;bi++;
                    c++;
                }
                ans=max(ans,c);
            }
        }
        cout<<ans;
        return 0;
    }
    

    Pascal :

    var
    s,s2:string;
    a:array[1..100]of string;
    i,j,t,m,h,k,o:integer;
    begin
     readln(s);readln(s2);s:=s+s2;
     t:=length(s);
     for i:=1 to t-1 do
     begin
      m:=i+1;
      for j:=1 to m do a[j]:=copy(s,j,t-i);
      for h:=1 to m do
      for k:=1 to m do
      if (a[h]=a[k])and(h<>k) then begin o:=length(a[h]);writeln(o); exit;end;
     end;
    end.
    
    
    • 1

    Information

    ID
    16641
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By