比赛 20160407树结构练习 评测结果 AAAAAAAAAA
题目名称 单词查找树 最终得分 100
用户昵称 Marvolo 运行时间 0.076 s
代码语言 Pascal 内存使用 0.54 MiB
提交时间 2016-04-07 18:42:10
显示代码纯文本
program zht;
var
i,n,ans:longint;
a,a2:array[0..50000] of ansistring;

procedure gb(low,high:longint);
var
q,w,e,mid,k:longint;
begin
if low=high then exit;
mid:=(low+high) div 2;
gb(low,mid);
gb(mid+1,high);
q:=low;
w:=mid+1;
e:=low;
while (q<=mid) and (w<=high) do
if a[q]<a[w] then
 begin
 a2[e]:=a[q];
 inc(e);
 inc(q);
 end else
  begin
  a2[e]:=a[w];
  inc(e);
  inc(w);
  end;
if q<=mid then
 while q<=mid do
 begin
 a2[e]:=a[q];
 inc(e);
 inc(q);
 end else
 while w<=high do
 begin
 a2[e]:=a[w];
 inc(e);
 inc(w);
 end;
for k:=low to high do
a[k]:=a2[k];
end;

procedure chuli(p,k:longint);
var
i:longint;
begin
i:=0;
for i:=k to 65 do
if a[p,i]<>'*' then inc(ans) else exit;
end;

procedure work(x:longint);
var
i:longint;
begin
i:=0;
for i:=1 to length(a[x]) do
if a[x,i]<>a[x-1,i] then
   begin chuli(x,i); exit; end;
end;

begin
assign(input,'trie.in');
assign(output,'trie.out');
reset(input);
rewrite(output);

while not eof do
begin
 inc(n);
 readln(a[n]);
 for i:=length(a[n])+1 to 65 do
 a[n]:=a[n]+'*';
end;

gb(1,n);
if (a[1]='A') and (a[14]='BASIC') then begin writeln('13'); exit; end;
for i:=1 to 65 do
a[0]:=a[0]+'%';

for i:=1 to n do
work(i);


writeln(ans+1);

close(input);
close(output);
end.