首页 > 代码库 > poj2406 周期

poj2406 周期

脑残wa了一次

 1 var  s:ansistring;
 2      ans,i,k,m:longint;
 3      pre:array[0..1010000] of longint;
 4 function max(x,y:longint):longint;
 5  begin
 6  if x>y then exit(x) else exit(y);
 7  end;
 8 procedure main;
 9  begin
10  pre[1]:=0;k:=0;
11  for i:=2 to length(s) do
12   begin
13    while (k<>0) and (s[k+1]<>s[i]) do k:=pre[k];
14    if s[k+1]=s[i] then inc(k);
15    pre[i]:=k;
16   end;
17  m:=length(s);
18  if m mod (m-pre[m])=0 then writeln(m div (m-pre[m])) else writeln(1);
19  end;
20 begin
21  while true do
22   begin
23   readln(s);if s=. then break;
24   main;
25   end;
26 end.          
View Code