Moderator: Board moderators


const
lowc=char(ord(32));
highc=char(ord(127));
maxs=1000;
type
trie=^trienode;
trienode=array[lowc..highc] of trie;
var
s:array[1..maxs] of char;
k,i,j,ss:integer;
a:trie;
res:longint;
procedure readf;
var
c:char;
begin
new(a);
for c:=lowc to highc do a^[c]:=nil;
read(c);
while (ord(c)<32) or (ord(c)>127) do read(c);
ss:=0;
while (7=7) do
begin
inc(ss);
s[ss]:=c;
read(c);
if (ord(c)<32) or (ord(c)>127) then break;
end;
end;
procedure check(x,y:integer);
var
i:integer;
p,q:trie;
c:char;
begin
p:=a;
for i:=x to y do
if p^[s[x]]=nil then
begin
new(q);
for c:=lowc to highc do q^[c]:=nil;
p^[s[x]]:=q;
p:=q;
inc(res);
end else p:=p^[s[x]];
end;
BEGIN
read(k);
while k>0 do
begin
dec(k);
readf;
res:=0;
for i:=1 to ss do check(i,ss);
writeln(res);
end;
END.
abcd= (n) + (n-1) + (n-2) + ...
abcd
bcd
cd
d
abab = 1(abab) + 2(aba,bab) + (3-1) { ab,ba,ab} + {4 -2} (a,b} =7
ab
abab(2)
b (0)
bab (1)
Users browsing this forum: No registered users and 0 guests