记录编号 |
607 |
评测结果 |
AAATWAAT |
题目名称 |
[NOIP 2002]字串变换 |
最终得分 |
62 |
用户昵称 |
zhai |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
2.176 s |
提交时间 |
2008-07-19 21:26:52 |
内存使用 |
0.11 MiB |
显示代码纯文本
program str;
const
rmax=6;
limit=10;
smax=20;
var
rule:array[1..rmax,1..2]of string[smax];
st,nd:string;
best:integer;
rulemax:integer;
procedure init;
var
temp:string;
begin
assign(input,'string.in');reset(input);
assign(output,'string.out');rewrite(output);
readln(temp);
st:=copy(temp,1,pos(' ',temp)-1);
nd:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
rulemax:=0;
while not eof do begin
inc(rulemax);
readln(temp);
rule[rulemax,1]:=copy(temp,1,pos(' ',temp)-1);
rule[rulemax,2]:=copy(temp,pos(' ',temp)+1,length(temp)-pos(' ',temp));
end;
end;
procedure try(now:string;step:integer);
var
k,temp:integer;
stemp:string;
begin
for k:=1 to rulemax do begin
if length(now)+length(rule[k,2])-length(rule[k,1])<115
then begin
temp:=pos(rule[k,1],now);
if temp<>0 then begin
stemp:=copy(now,1,temp-1)+rule[k,2]
+copy(now,temp+length(rule[k,1]),115);
if stemp=nd then begin
if step<best then best:=step;
end
else if step<best then try(stemp,step+1);
end;
end;
end;
end;
begin
init;
best:=limit+1;
try(st,1);
if best<limit then writeln(best)
else writeln('NO ANSWER!');
end.