ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1423. String Tale

Why Compilation Error??? 2
Posted by Assassin 15 Jan 2008 16:06
type vector=array[0..750000] of longint;

var n:longint;
    s,t:ansistring;
    x:longint;

function qqq(s,t:ansistring):longint;
  var f:vector;
      k,i:longint;
      result:longint;
  begin
    result:=-1;
    f[1]:=0;
    k:=0;
    for i:=2 to length(s) do
      begin
        while (k>0) and (s[k+1]<>s[i]) do k:=f[k];
        if s[k+1]=s[i] then inc(k);
        f[i]:=k;
      end;
    k:=0;
    for i:=1 to length(t) do
      begin
        while (k>0) and (s[k+1]<>t[i]) do k:=f[k];
        if s[k+1]=t[i] then inc(k);
        if k=length(s)
          then
            begin
              result:=i+length(t);
              break;
            end;
      end;
    qqq:=result;
  end;

begin
  readln(n);
  readln(s);
  readln(t);
  x:=qqq(s,t+t);
  writeln(x mod length(s));
  readln;
end.