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

poj1961 Period 2012-01-11

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

标签:

http://162.105.81.212/JudgeOnline/problem?id=1961

_____________________________________

 也是求最长重复字串。
_____________________________________

 1 Program Stone;
 2 var i,j,n,m:longint;
 3     s:ansistring;
 4     b:array[1..1000000]of longint;
 5 Begin
 6  assign(input,input.in);reset(input);
 7    readln(n);
 8    while n<>0 do
 9     begin
10        readln(s);
11        inc(m);
12        j:=0;b[1]:=0;
13        writeln(Test case #,m);
14        for i:=2 to n do
15         begin
16           while (j>0)and(s[i]<>s[j+1]) do j:=b[j];
17           if s[i]=s[j+1] then inc(j);
18           b[i]:=j;
19           if (i mod (i-b[i])=0)and(b[i]<>0) then writeln(i, ,i div (i-b[i]));
20         end;
21        writeln;
22        readln(n);
23     end;
24 end.
25 
26  

 

poj1961 Period 2012-01-11

标签:

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

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