正确 
   正确
   正确
   正确
   错误
   正确
   错误
   错误
   错误求连续正确和错误的最大次数?分别为4和3

解决方案 »

  1.   

    假定存储在一个String数组里
    var
      MaxRightCount, MaxErrorCount, OldCount, i: Integer;
      OldString: string;
    begin
      MaxErrorCount := 0;
      MaxRightCount := 0;
      OldCount := 0;
      OldString := '';
      for i := Low(StrArray) to High(StrArray) do
      begin
        if StrArray[i] = OldString then
          Inc(OldCount)
        else
        begin
          if OldString = '正确' then
          begin
            if OldCount > MaxRightCount then
              MaxRightCount := OldCount;
          end
          else
          begin
            if OldCount > MaxErrorCount then
              MaxErrorCount := OldCount;
          end;
          OldCount := 0;
          OldString := StrArray[i];
        end;
      end;
      if OldString = '正确' then
      begin
        if OldCount > MaxRightCount then
          MaxRightCount := OldCount;
      end
      else
      begin
        if OldCount > MaxErrorCount then
          MaxErrorCount := OldCount;
      end;
    end;
      

  2.   

    好像有问题?
     OldString := ''; 
      for i := Low(StrArray) to High(StrArray) do 
      begin 
        if StrArray[i] = OldString then 
          Inc(OldCount) 
    还有怎么都是判断正确?
      

  3.   

      procedure   TForm1.Button1Click(Sender:   TObject);   
      function   SchStr(s:   string):   integer;   
      var   
          i,   startS,   endS:   integer;   
      begin   
          startS   :=   -1;   
          endS   :=   -1;   
          for   i:=0   to   (Memo1.Lines.Count-1)   do   
          begin   
              if   (Trim(Memo1.Lines[i])=s)   then   
              begin   
                  if   startS<0   then   
                      startS   :=   i;   
              end   
              else   
              begin   
                  if   (endS<0)   and   (startS>=0)   then   
                      endS   :=   i;   
              end;   
          end;   
          Result   :=   endS   -   startS;   
      end;   
      begin   
          ShowMessage(IntToStr(SchStr('23')));   
      end;
      

  4.   

    什么问题?
    怎么会都判断正确?不是有else吗?
      

  5.   

    假设所有字符保存在tmpList:TStringList中
    var
       i,j,max1,max2:integer;
       LastStr : string;
    begin
       LastStr :='';
       max1 :=0;
       max2:=0;
       j:=1;
       for i:=0 to  tmpList.Count-1 do
           begin
              if LastStr = tmpList.Strings[i] then
                  inc(j)
              else
                  begin
                     if   tmpList.Strings[i] = '正确' then
                          max2 := max(max2,j)
                     else
                          max1 := max(max1,j);
                     j :=1;
                     LastStr := tmpList.Strings[i]
                  end;
           end;
      

  6.   

    其中max1为正确的最大个数,max2为错误的最大个数
      

  7.   


    function FindMaxStringCnt(strToken:string;strs:TStrings):integer;
    var
       i,iPos,maxCnt,cnt:integer;
       LastStr:string;
    begin
        maxCnt:=0;
        cnt:=1;
        LastStr:=strToken;
        iPos:=strs.IndexOf(strToken);
        for i:=iPos+1 to strs.Count-1 do
        begin
            if (LastStr=strs.Strings[i]) then
                inc(cnt)
            else
                cnt:=1;
            maxCnt:=max(cnt,maxCnt);
            LastStr:=strs.Strings[i];
        end;
        Result:=maxCnt;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
        Label1.Caption:=IntToStr(FindMaxStringCnt('错误',Memo1.Lines));
        Label2.Caption:=IntToStr(FindMaxStringCnt('正确',Memo1.Lines));
    end;
      

  8.   

    程序运行后,TCount存放的是正确的个数,FCount存放的是错误的个数
    procedure GetCount(ss:TStringList;var TCount,Fcount:integer);
    var
    i:integer;
    begin
    TCount:=0;
    Fcount:=0;
    for i:=0 to ss.Count-1 do
      begin
      if trim(ss[i])='正确' then
         TCount:=TCount+1;
      if trim(ss[i])='错误' then
         FCount:=FCount+1;
      end;
    end;