码迷,mamicode.com
首页 > 其他好文 > 详细

pku3461 Oulipo 2012-01-11

时间:2016-03-02 21:35:19      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

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.

 

pku3461 Oulipo 2012-01-11

标签:

原文地址:http://www.cnblogs.com/yesphet/p/5236481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!