pku3461 Oulipo 2012-01-11

http://162.105.81.212/JudgeOnline/problem?id=3461

 1 Program stone;
 2 var i,j,k,n,ans:longint;
 3     w,s:ansistring;
 4     b:array[1..10000]of longint;
 5 Begin
 6   assign(input,'input.in');reset(input);
 7    readln(n);
 8    for k:=1 to n do
 9     begin
10         readln(w);
11         readln(s);
12         ans:=0;
13         j:=0;b[1]:=0;
14         for i:=2 to length(w) do
15          begin
16             while (j>0)and(w[i]<>w[j+1]) do j:=b[j];
17             if w[i]=w[j+1] then inc(j);
18             b[i]:=j;
19          end;
20         j:=0;
21         for i:=1 to length(s) do
22          begin
23            while  (j>0)and(s[i]<>w[j+1]) do j:=b[j];
24            if s[i]=w[j+1] then inc(j);
25            if j=length(w) then begin
26                                   inc(ans);
27                                   j:=b[j];
28                                end;
29          end;
30         writeln(ans);
31     end;
32 end.

 

posted on 2016-03-02 20:53  Yesphet  阅读(108)  评论(0编辑  收藏  举报