记录编号 3380 评测结果 AAAAWAAA
题目名称 [NOIP 2002]字串变换 最终得分 87
用户昵称 Gravatar打不死的羊 是否通过 未通过
代码语言 Pascal 运行时间 0.290 s
提交时间 2008-10-06 20:09:53 内存使用 73.35 MiB
显示代码纯文本
program ex;
Type
fxz1=array[1..100000]of string;
var
zf,a,b:fxz1;
f1,f2:text;
j,m2,left,right,p,q,n,m,l,k,i,step,ans:longint;
x,y,s,ls:string;
begin
assign(f1,'string.in');
assign(f2,'string.out');
reset(f1);rewrite(f2);
n:=0;
readln(f1,s);
l:=pos(' ',s);
x:=copy(s,1,l-1);
y:=copy(s,l+1,length(s)-l);
while not(eof(f1)) do
begin
inc(n);
readln(f1,s);
l:=pos(' ',s);
a[n]:=copy(s,1,l-1);
b[n]:=copy(s,l+1,length(s)-l);
end;
step:=0;
zf[1]:=x;
left:=1;right:=1;
 while (step<10)and(ans=0) do
 begin
  p:=left;q:=right;
  left:=right+1;inc(step);
  for i:=p to q do
  for k:=1 to n do
  begin
   ls:=zf[i];
   m:=pos(a[k],ls);m2:=m;
   if m<>0 then begin
                inc(right);
                ls:='';
                for j:=1 to m-1+length(a[k]) do ls:=ls+' ';
                ls:=ls+copy(zf[i],m+length(a[k]),length(zf[i])-m-length(a[k]));
                zf[right]:=copy(zf[i],1,m-1)+b[k]+copy(zf[i],m+length(a[k]),length(zf[i])-m-length(a[k])+1);
                if zf[right]=y then ans:=step;
                while (m<>0)and(ans<>0) do
                begin
                m:=pos(a[k],ls);
                if (m<>0)and(m>m2) then
                 begin
                 inc(right);
                 zf[right]:=copy(zf[i],1,m-1)+b[k]+copy(ls,m+length(a[k]),length(ls)-m-length(a[k]));
                 if zf[right]=y then ans:=step;
                 ls:='';
                 for j:=1 to m-1+length(a[k]) do ls:=ls+' ';
                 ls:=ls+copy(zf[i],m+length(a[k]),length(zf[i])-m-length(a[k]));
                 m2:=m;
                 end;
                end;end;
  end;
  end;
if ans<>0 then writeln(f2,ans)
          else writeln(f2,'NO ANSWER!');
close(f1);close(f2);
end.