字符串abcdef123与
      xbcyzf123相同位置下相似的有bc和f123.我想让其返回的数据相同数为4而不是为2

解决方案 »

  1.   

    写的有点烂,凑乎着用var str, Ms, str1: string;
      maxl, i, j, tmpmax: integer;
    begin
      str := 'abcdef123';
      str1 := 'xbcyzf123';
      for j := 1 to length(str) do
      begin
        for i := length(str) downto 1 do
        begin
          ms := copy(str, j, i);
          if pos(ms, str1) > 0 then
          begin
            maxl := length(ms);
            if tmpmax < MAXL then
              tmpmax := maxl;
          end;
        end;
      end;
      showmessage(inttostr(tmpmax));
    end;
      

  2.   


      a b c d e f 1 2 3
    x - - - - - - - - -
    b - * - - - - - - -
    c - - * - - - - - -
    y - - - - - - - - -
    z - - - - - - - - -
    f - - - - - * - - -
    1 - - - - - - * - -
    2 - - - - - - - * -
    3 - - - - - - - - *
    斜着的 * 线最长的就是。
      

  3.   

    var   str,   Ms,   str1:   string; 
          i,   j,   tmpmax:   integer; 
    begin 
        i:=0;
        str   :=   'abcdef123'; 
        str1   :=   'xbcyzf123'; 
        for   j   :=   0   to   Min(length(str),length(str1))-1   do 
        begin 
          if str[j]=str1[j] then 
          begin
             inc(i);   
             tmpMax:=i;    
          end
          else if str[j]<>str1[j] then
          begin   
            tmpMax:=Max(tmpMax,i);
            i:=0;
          end
        end; 
        showmessage(inttostr(tmpmax)); 
    end;