WORDCNT - Word Counting

Tác giả: RR

Ngôn ngữ: Pascal

uses math;
var
  test:longint;
  s:ansistring;
  f,a:array[0..1011] of longint;
  n,i,res:longint;

begin
  readln(test);
  for test:=1 to test do
    begin
      readln(s);
      while s[1]=' ' do delete(s,1,1);
      while pos('  ',s)>0 do delete(s,pos('  ',s),1);
      while s[length(s)]=' ' do delete(s,length(s),1);
      s:=s+' ';
      n:=0;
      while pos(' ',s)>0 do
        begin
          inc(n); a[n]:=pos(' ',s)-1;
          delete(s,1,pos(' ',s));
        end;

      res:=0;
      for i:=1 to n do
        begin
          if a[i]=a[i-1] then f[i]:=f[i-1]+1
          else f[i]:=1;
          res:=max(res,f[i]);
        end;
      writeln(res);
    end;
end.

Download