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 |
额……求助……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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator