| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为何WAvar
n,i : longint;
s,t : ansistring;
next : array[1..100000] of longint;
procedure compute_next;
var
k,q : integer;
begin
k := 0; next[1] := 0;
for q := 2 to length(t) do begin
while (k > 0) and (t[q] <> t[k+1]) do k := next[k];
if t[q] = t[k+1] then inc(k);
next[q] := k;
end;
end;
function kmp : longint;
var
k,q : integer;
begin
compute_next;
k := 0; kmp := 0;
for q := 1 to length(s) do begin
while (k > 0) and (s[q] <> t[k+1]) do k := next[k];
if s[q] = t[k+1] then inc(k);
if k = length(t) then begin
inc(kmp);
k := next[k];
end;
end;
end;
begin
readln(n);
for i := 1 to n do begin
readln(t); readln(s);
writeln(kmp);
end;
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator