记录编号 |
679 |
评测结果 |
AAAATAAT |
题目名称 |
[NOIP 2002]字串变换 |
最终得分 |
75 |
用户昵称 |
苏轼 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
2.020 s |
提交时间 |
2008-07-20 16:56:14 |
内存使用 |
0.12 MiB |
显示代码纯文本
program stringl;
var a,b:string;
c:array[0..8,1..2]of string;
n,min:integer;
txt,f:text;
procedure search(ji:integer; s:string);
var i,j,k:integer;
add:array[0..20]of integer;
tmp:string;
txt:text;
begin
if (ji>11)or(s=b) then
begin
min:=ji-1;
exit;
end;
for i:=1 to n do
begin
for j:=0 to 20 do
add[j]:=0;
tmp:=s;
j:=0;
repeat
if pos(c[i,1],tmp)<>0 then
begin
inc(j);
add[j]:=add[j-1]+pos(c[i,1],tmp);
delete(tmp,pos(c[i,1],tmp),length(c[i,1]));
end;
until pos(c[i,1],tmp)=0;
tmp:=s;
for k:=1 to j do
begin
delete(s,add[k],length(c[i,1]));
insert(c[i,2],s,add[k]);
if length(s)<20 then
search(ji+1,s);
s:=tmp;
end;
end;
end;
begin
assign(txt,'string.in');
reset(txt);
readln(txt,a);
writeln(a);
b:=copy(a,pos(' ',a)+1,length(a)-pos(' ',a));
write(b,' ');
a:=copy(a,1,pos(' ',a)-1);
writeln(a);
repeat
inc(n);
readln(txt,c[n,1]);
c[n,2]:=copy(c[n,1],pos(' ',c[n,1])+1,length(c[n,1])-pos(' ',c[n,1]));
c[n,1]:=copy(c[n,1],1,pos(' ',c[n,1])-1);
until eof(txt);
search(1,a);
assign(f,'string.out');
rewrite(f);
if min<=10 then writeln(f,min)
else writeln(f,'NO ANSWER!');
close(f);
end.