📄 ac1205.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 + -