⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1205.pas

📁 同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料
💻 PAS
字号:
program tju1205;
const
  maxl=32768;
var
  c:array[1..maxl]of char;
  w,start,len,pre:array[1..maxl]of word;
  last:array[0..26]of word;
  n,p,i,j:word;
  s:string;
procedure sort(s,t,p:word);
  var
    fin:array[0..26]of word;
    i,x:word;
  begin
    if s>=t then exit;
    for i:=s to t do begin
      if p>len[w[i]] then x:=0 else x:=ord(c[start[w[i]]+p])-64;
      pre[w[i]]:=last[x];last[x]:=w[i];
    end;
    i:=s-1;
    for x:=0 to 26 do begin
      while last[x]>0 do begin
        inc(i);w[i]:=last[x];last[x]:=pre[last[x]];
      end;
      fin[x]:=i;
    end;
    for x:=1 to 26 do
      sort(fin[x-1]+1,fin[x],p+1);
  end;
begin
  repeat
    n:=0;p:=0;
    repeat
      readln(s);
      if s='*' then break;
      inc(n);w[n]:=n;start[n]:=p;len[n]:=length(s);
      for i:=1 to len[n] do begin
        inc(p);c[p]:=s[i];
      end;
    until false;

    sort(1,n,1);

    for i:=2 to n do begin
      j:=1;
      while (j<=len[w[i-1]]) and (j<=len[w[i]]) and
            (c[start[w[i-1]]+j]=c[start[w[i]]+j]) do begin
        dec(p);inc(j);
      end;
    end;
    writeln(p+1);
  until seekeof;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -