记录编号 | 4263 | 评测结果 | AAAAEAAE | ||
---|---|---|---|---|---|
题目名称 | [NOIP 2002]字串变换 | 最终得分 | 75 | ||
用户昵称 | 是否通过 | 未通过 | |||
代码语言 | Pascal | 运行时间 | 1.046 s | ||
提交时间 | 2008-10-15 21:52:41 | 内存使用 | 24.65 MiB | ||
program coder; var a,b:array[1..255] of string; s1,s2,x,y:string; c:array[1..100000] of string; f1,f2:text; flag:boolean; h,g,i,j,l,k,m,n,t,times:longint; total,tou,wei,t1,t2:longint; procedure bfs; var i,j,k,v:longint; now,s3:string; begin c[1]:=x; flag:=false; for k:=1 to 10 do begin total:=0; for i:=t1 to t2 do begin for j:=1 to n do begin s3:=''; t:=pos(a[j],c[i]); if t>0 then begin inc(wei); c[wei]:=copy(c[i],1,t-1)+b[j]+copy(c[i],t+length(a[j]),length(c[i])-(t+length(a[j]))+1); if c[wei]=y then begin writeln(f2,k);close(f1);close(f2);halt;end; for v:=1 to length(b[j]) do s3:=s3+' '; now:=copy(c[i],1,t-1)+s3+copy(c[i],t+length(a[j]),length(c[i])-(t+length(a[j]))+1); h:=pos(a[j],now); if h>0 then begin g:=h; s2:=c[i]; s1:=''; times:=0; while g>0 do begin s1:=s1+copy(s2,1,pos(a[j],s2)); delete(s2,1,pos(a[j],s2)); g:=pos(a[j],s2); if g>0 then begin inc(wei); c[wei]:=s1+copy(s2,1,g-1)+b[j]+copy(s2,g+length(a[j]),length(s2)-(g+length(a[j]))+1); if c[wei]=y then begin writeln(f2,k);close(f1);close(f2);halt;end; end; end; end; end; end; end; tou:=t2+1; t1:=tou;t2:=wei; end; end; begin assign(f1,'string.in');reset(f1); assign(f2,'string.out');rewrite(f2); readln(f1,s1); i:=1; while s1[i]<>' ' do inc(i); x:=copy(s1,1,i-1); y:=copy(s1,i+1,length(s1)-i); j:=1; while not(eof(f1)) do begin s1:=''; readln(f1,s1); i:=1; while s1[i]<>' ' do inc(i); a[j]:=copy(s1,1,i -1); b[j]:=copy(s1,i+1,length(s1)-i); inc(j); end; n:=j-1; tou:=1;wei:=1; t1:=1;t2:=1; bfs; writeln(f2,'NO ANSWER!'); close(f2); end.