比赛 20160407树结构练习 评测结果 AAAAAAAAAA
题目名称 单词查找树 最终得分 100
用户昵称 Twist Fate 运行时间 0.025 s
代码语言 Pascal 内存使用 61.20 MiB
提交时间 2016-04-07 19:33:57
显示代码纯文本
program cjen;
var
	a:array[1..250000] of string;
	i,j,n,t:longint;
procedure q(l,r:longint);
var
	mid,p:string;
	i,j:longint;
begin
	i:=l;	j:=r;
	mid:=a[(l+r) div 2];
	repeat
		while a[i]<mid do inc(i);
		while a[j]>mid do dec(j);
		if i<=j then begin
			p:=a[i];	a[i]:=a[j];	a[j]:=p;
			inc(i);	dec(j);
		end;
	until i>j;
	if i<r then q(i,r);
	if l<j then q(l,j);
end;
begin
	assign(input,'trie.in');	reset(input);
	assign(output,'trie.out');	rewrite(output);
	while not eof do begin
		n:=n+1;
		readln(a[n]);
	end;
	q(1,n);
	t:=length(a[1]);
	for i:=2 to n do begin
		j:=1;
		while (a[i][j]=a[i-1][j]) and (j<=length(a[i-1])) do inc(j);
		t:=t+length(a[i])-j+1;
	end;
	inc(t);
	writeln(t);
	close(input);	close(output);
end.