记录编号 6614 评测结果 AAATWAAT
题目名称 [NOIP 2002]字串变换 最终得分 62
用户昵称 Gravatarname:弓虽 是否通过 未通过
代码语言 Pascal 运行时间 2.102 s
提交时间 2008-11-03 15:42:35 内存使用 0.17 MiB
显示代码纯文本
program stringex(input,output);
var
 flag:boolean;
 s,x1,s1:string;
 s2,x:array[1..100] of ansistring;
q, c,min:longint;

procedure p(s:ansistring);
var
 i,k:longint;
 temp:string;
begin
 if s=x1 then begin
            flag:=false;
            if c<min then min:=c;
            exit;
          end;
          if c>min then exit;
 for i:=1 to q do
  if length(s)+length(s2[i])-length(x[i])<115 then begin
   k:=pos(s2[i],s);
  if k<>0 then begin
   temp:=s;
   delete(temp,k,length(s2[i]));
   insert(x[i],temp,k);
   inc(c);
   p(temp);
   dec(c);
  end;
 end;
end;
begin
 assign(input,'string.in');
 assign(output,'string.out');
 reset(input);
 rewrite(output);
 readln(x1);
 s:= copy(x1,1,pos(' ',x1)-1);
 delete(x1,1,pos(' ',x1));
 q:=0;
 while not eof(input) do begin
  readln(s1);
  inc(q);
  s2[q]:=copy(s1,1,pos(' ',s1)-1);
  delete(s1,1,pos(' ',s1));
  x[q]:=s1;
 end;
 min:=10; flag:=true; c:=0;
 p(s);
 if flag=true then writeln('NO ANSWER!')
         else writeln(min);
 close(input);
 close(output);
end.