ArinaRaguzina

Untitled

Oct 8th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. program Arina;
  2. {$H+}
  3. var
  4. s: string;
  5. n, i, k,sum: integer;
  6. pref: array [1..150000] of integer;
  7. begin
  8. Assign(input, 'input.txt');
  9. Assign(output, 'output.txt');
  10. reset(input);
  11. rewrite(output);
  12. Readln(s);
  13. n := Length(s);
  14. k := 0;
  15. for i := 2 to n do begin
  16. while (k > 0) and (s[k+1] <> s[i]) do
  17. k := pref[k];
  18. if s[k+1] = s[i] then
  19. k+=1;
  20. pref[i] := k;
  21. end;
  22. for i := 1 to n do
  23. sum+=pref[i];
  24. Write(sum);
  25. Close(input);
  26. Close(output);
  27. end.
Advertisement
Add Comment
Please, Sign In to add comment