Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

额……求助……

Posted by xycking at 2010-03-14 11:53:51 on Problem 2406
kmp,就是不对啊,我甚至找了一个标程来对,都没发现错误
program Project1;
var
next,a:array[0..1000100]of integer;
s,i,j,k,t,d:integer;
b       : ansistring ;
x:char;
begin
  assign(input,'pku_2406.in');
  assign(output,'pku_2406.out');
  reset(input);
  rewrite(output);
  while true do
  begin
    s:=0;
    fillchar(a,sizeof(a),0);
    fillchar(next,sizeof(next),0);
    {while not(eoln) do
    begin
      read(x);
      if x='.' then begin
        close(input);
        close(output);
        halt;
      end;
      inc(s);
      a[s]:=ord(x);
    end;}
    readln(b);
    if b='.' then break;
    s:=length(b);
    if s=1 then writeln(1) else begin
    for i:=1 to s do a[i]:=ord(b[i]);
    next[1]:=0;
    next[0]:=-1;
    for i:=1 to s do
    begin
      k:=next[i-1];
      while (a[i]<>a[k+1])and(k>=0) do k:=next[k];
      next[i]:=k+1;
    end;
    d:=s-next[s];
    if s mod d=0 then t:=s div d else t:=1;
    writeln(t);
    end;
  end;
  close(input);
  close(output);
end.


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator