还是字符串,继续贴pascal。
还是对不起咯~
博客正在慢慢写。
目前的题目难度的确不是很高。
但是难得我也不会。
所以我会发一些有难度但是不至于我们做不出来的题目。(ms.27的朋友们)
type jj=record
s:string;
d:longint;
end;
var
head,tail:array[1..2] of longint;
q:array[1..10000,1..2] of jj;
all,b,i:longint;
st:string;
a:array[1..10,1..2] of string;
procedure check(st:string;t:longint);
var
i:longint;
pd:boolean;
begin
pd:=false;
for i:=1 to tail[t]-1 do
if q[i,t].s=st then pd:=true;
if pd then dec(tail[t])
else
for i:=1 to tail[3-t] do
if q[i,3-t].s=st then
begin
writeln(q[tail[t],t].d+q[i,3-t].d);
halt;
end;
end;
procedure expand(t:longint);
var
i:longint;
begin
for i:=2 to all do
begin
b:=pos(a[i,t],q[head[t],t].s);
if b<>0 then
begin
repeat
inc(tail[t]);
q[tail[t],t].s:=q[head[t],t].s;
delete(q[tail[t],t].s,b,length(a[i,t]));
insert(a[i,3-t],q[tail[t],t].s,b);
q[tail[t],t].d:=q[head[t],t].d+1;
check(q[tail[t],t].s,t);
b:=b+pos(a[i,t],copy(q[head[t],t].s,b+1,length(q[head[t],t].s)-b));
until pos(a[i,t],copy(q[head[t],t].s,b+1,length(q[head[t],t].s)-b))=0;
end;
end;
inc(head[t]);
end;
procedure init;
begin
while not eoln do
begin
inc(all);
readln(st);
b:=pos(' ',st);
a[all,1]:=copy(st,1,b-1);
a[all,2]:=copy(st,b+1,length(st)-b);
end;
q[1,1].s:=a[1,1];
q[1,2].s:=a[1,2];
head[1]:=1; tail[1]:=1;
head[2]:=1; tail[2]:=1;
repeat
if (head[1]<=tail[1]) and (q[tail[1],1].d<=10) and (tail[1]<=tail[2]) then expand(1);
if (head[2]<=tail[2]) and (q[tail[2],2].d<=10) and (tail[1]>tail[2]) then expand(2);
until ((head[1]>tail[1]) or (head[2]>tail[2])) or (q[tail[1],1].d+q[tail[2],2].d>10);
end;
begin
init;
writeln('NO ANSWER!');
end.