node2=record
a,b:string;
end;
node=record
top,tail:longint;
size:array[0..10000] of longint;
st:array[0..10000] of string;
end;
var
st,s1,s2:string;
t:longint;
que:array[0..1] of node;
s:array[0..6] of node2;
ff:boolean;
procedure expand(k:longint);
var
a,c,b,now,tmp,nn:string;
i,q,p,len1,len2:longint;
f:boolean;
begin
inc(que[k].top);
now:=que[k].st[que[k].top];
for i:=1 to t do
begin
a:=s[i].a; b:=s[i].b;
if k=1 then
begin
c:=a; a:=b; b:=c;
end;
len1:=length(now); len2:=length(a);
tmp:=now;
while pos(a,now)<>0 do
begin
c:=copy(tmp,1,pos(a,now)-1);
c:=c+b+copy(tmp,pos(a,now)+len2,length(tmp));
f:=true;
for p:=1 to que[1-k].tail do
if c=que[1-k].st[p] then
begin
writeln(que[k].size[que[k].top]+que[1-k].size[p]+1);
halt;
end;
for p:=1 to que[k].tail do
if c=que[k].st[p] then
begin
f:=false; break;
end;
if f then
begin
inc(que[k].tail);
que[k].st[que[k].tail]:=c;
que[k].size[que[k].tail]:=que[k].size[que[k].top]+1;
end;
nn:='';
for p:=1 to len2 do nn:=nn+' ';
now:=copy(now,1,pos(a,now)-1)+nn+copy(now,pos(a,now)+len2,length(now));
end;
end;
end;
begin
readln(st);
s1:=copy(st,1,pos(' ',st)-1);
s2:=copy(st,pos(' ',st)+1,length(st)-pos(' ',st));
t:=0;
while not eof do
begin
readln(st);
inc(t);
s[t].a:=copy(st,1,pos(' ',st)-1);
s[t].b:=copy(st,pos(' ',st)+1,length(st)-pos(' ',st));
end;
que[1].top:=0; que[1].tail:=1; que[1].st[1]:=s2;
que[0].top:=0; que[0].tail:=1; que[0].st[1]:=s1;
que[1].size[1]:=0; que[0].size[1]:=0;
repeat
if (((que[0].tail=que[0].top)or(que[0].size[que[0].tail]=10))
and((que[1].tail=que[1].top)or(que[1].size[que[1].tail]=10)))or
(que[0].size[que[0].top]+que[1].size[que[1].top]>10) then
begin
writeln('NO ANSWER!');
halt;
end;
ff:=true;
if ff and(que[0].tail=que[0].top) then
begin
expand(1);
ff:=false;
end;
if ff and (que[1].tail=que[1].top) then
begin
expand(0);
ff:=false;
end;
if ff and (que[0].tail<que[1].tail) then expand(0) else expand(1);
until false;
end.
状态: Unaccepted
测评机: Xeond[6]
得分: 40分
提交日期: 2010-9-7 20:00:00
有效耗时: 360毫秒
测试结果1: 通过本测试点|有效耗时219ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 运行错误|普通保护错误
测试结果4: 测试结果错误.错误结果为:1
正确结果应为:5
测试结果5: 输出过长|用户输出数据超过标准输出两倍[标准输出1位|选手输出10位]
测试结果6: 通过本测试点|有效耗时47ms
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 运行错误|普通保护错误
测试结果9: 测试结果错误.错误结果为:1
正确结果应为:5
测试结果10: 输出过长|用户输出数据超过标准输出两倍[标准输出1位|选手输出10位]