记录编号 125920 评测结果 AAAAA
题目名称 苦恼中的嘉豪 最终得分 100
用户昵称 Gravatarteacher 是否通过 通过
代码语言 Pascal 运行时间 0.011 s
提交时间 2014-10-10 17:44:30 内存使用 0.20 MiB
显示代码纯文本
var len:longint;
le:integer;
i,m:shortint;
n:string;
a,a1:array[1..10000] of char;
next:array[0..10000] of integer;

procedure kmp;
var i:integer;t:integer;
begin
 le:=length(n);
 next[1]:=0;
 for i:=2 to le do begin
  t:=i-1;
  while (n[next[t]+1]<>n[i]) and (t>0) do t:=next[t];
  next[i]:=t;
 end;
end;

procedure go;
var t,p,q,x,y,i,j:integer;
begin
 t:=1;
 y:=0;
 p:=0;
 q:=0;
 for i:=1 to len do begin
  if a[i]=n[t] then inc(t)
   else begin
    x:=next[i-1];
    while x>0 do
     if a[i]<>n[x+1] then x:=next[x]
      else t:=x+2;
   end;
  if t=le+1 then begin
   inc(y);
   for j:=p+1 to i-le do begin inc(q); a1[q]:=a[j]; end;
   p:=i;
   t:=1;
  end;
 end;
 for j:=p+1 to len do begin inc(q); a1[q]:=a[j]; end;
 a:=a1;
 if y>0 then writeln('Yes') else writeln('No');
 len:=q;
end;

begin
 assign(input,'Jiahao3.in'); reset(input);
 assign(output,'Jiahao3.out'); rewrite(output);
 len:=0;
 while not eoln do begin inc(len); read(a[len]); end;
 readln(m);
 next[0]:=0;
 for i:=1 to m do begin
  readln(n);
  kmp;
  go;
 end;
 close(input); close(output);
end.