记录编号 |
661 |
评测结果 |
AATWA |
题目名称 |
[NOIP 2002]字串变换 |
最终得分 |
30 |
用户昵称 |
chengyang |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.032 s |
提交时间 |
2008-07-20 14:37:47 |
内存使用 |
0.00 MiB |
显示代码纯文本
program stri(f1,f2);
const
rmax=6; limit=10;
smax=20;
var
rule:array[1..rmax,1..2] of string[20];
st,nd,temp:string;
best,max,i:integer;
f1,f2:text;
procedure try(now:string;step:integer);
var
k:integer; temp1:integer;
stemp:string;
begin
for k:=1 to max do begin
if length(now)+length(rule[k,2])-length(rule[k,1])<115 then
temp1:=pos(rule[k,1],now);
if temp1<>0 then begin
stemp:=copy(now,1,temp1-1)+rule[k,2]+copy(now,temp1+length(rule[k,1]),115);
if stemp=nd then begin
if step<best then best:=step;
end
else begin
if step<limit then try(stemp,step+1);
end;
end;
end
end;
Begin
assign(f1,'string.in'); assign(f2,'string.out');
reset(f1); rewrite(f2);
readln(f1,temp);
st:=copy(temp,1,pos(' ',temp)-1);
nd:=copy(temp,pos(' ',temp)+1,20);
max:=0;
while not eof(f1) do begin
readln(f1,temp);
max:=max+1;
rule[max,1]:=copy(temp,1,pos(' ',temp)-1);
rule[max,2]:=copy(temp,pos(' ',temp)+1,20);
end;
best:=limit+1;
try(st,1);
if best<limit then writeln(f2,best)
else writeln(f2,'NO ANSWER!');
close(f1);close(f2);
End.