记录编号 |
3005 |
评测结果 |
AAWAWAAT |
题目名称 |
[NOIP 2002]字串变换 |
最终得分 |
62 |
用户昵称 |
bly1991 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.014 s |
提交时间 |
2008-09-30 09:37:21 |
内存使用 |
24.53 MiB |
显示代码纯文本
program bly(input,ouput);
var
a:array[1..10,1..10000] of string;
rule:array[1..6,1..2] of string;
n,long,long0,deep,i,j,k,x:integer;
p:boolean;
st,st0:string;
f1,f2:text;
procedure th;
var
i0:integer;
begin
i0:=pos(rule[j,1],a[deep,i]);
a[deep+1,long0]:=a[deep,i];
delete(a[deep+1,long0],i0,length(rule[j,1]));
insert(rule[j,2],a[deep+1,long0],i0);
inc(long0);
end;
begin
assign(f1,'string.in');
reset(f1);
readln(f1,st);
a[1,1]:=copy(st,1,pos(' ',st)-1);
st0:=copy(st,pos(' ',st)+1,length(st)-1);
repeat
inc(n);
readln(f1,st);
rule[n,1]:=copy(st,1,pos(' ',st)-1);
rule[n,2]:=copy(st,pos(' ',st)+1,length(st)-1);
until eof(f1)=true;
p:=false;
deep:=1;
long0:=1;
repeat
long:=long0;
long0:=1;
for i:=1 to long do begin
for j:=1 to n do begin
if pos(rule[j,1],a[deep,i])<>0 then th;
end;
end;
for i:=1 to long0 do begin
if a[deep+1,i]=st0 then p:=true;
end;
x:=long0;
for i:=1 to long0 do begin
for j:=i+1 to long0 do begin
if (a[deep+1,i]=a[deep+1,j])and(a[deep+1,j]<>'') then begin
for k:=j to long0-1 do a[deep+1,k]:=a[deep+1,k+1];
dec(x);
end;
end;
end;
long0:=x;
if not(p=true) then inc(deep);
until (p=true)or(deep>=10);
assign(f2,'string.out');
rewrite(f2);
if p=true then write(f2,deep);
if deep>=10 then write(f2,'NO ANSWER');
close(f2);
end.