[POJ1961] Period/[NKOI2201] 周期

本文详细阐述了如何处理和解析复杂字符串的测试案例,包括使用特定算法进行字符串匹配和分解,通过实例展示了代码实现过程。

传送门

http://oi.nks.edu.cn/showproblem?problem_id=2201
http://poj.org/problem?id=1961

题解

[POJ2406] Power Strings

const
 maxn=1000005;
var
 next:array[0..maxn]of longint;
 i,j,k:longint;
 n,m:longint;
 a:ansistring;
begin
 m:=0;
 while not eof do
  begin
   readln(n); if n=0 then break;
   readln(a); inc(m);
   next[1]:=0; j:=0;
   for i:=2 to n do
    begin
     while (j>0)and(a[j+1]<>a[i]) do j:=next[j];
     if a[j+1]=a[i] then inc(j);
     next[i]:=j;
    end;
   writeln('Test case #',m);
   for i:=2 to n do
    if (i mod (i-next[i])=0)and(i div (i-next[i])>1)
    then writeln(i,' ',i div (i-next[i]));
   writeln;
  end;
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值