fork download
  1. program casino;
  2. const max=40000;
  3. type testo=array[0..max] of array[0..max] of char;
  4. subtesto=array[0..max] of char;
  5. ps=array[0..max] of longint;
  6. var N,M,i,j,z,coppie:longint;
  7. str:testo;
  8. A,B:subtesto;
  9. c:char;
  10. lps: array[0..max] of longint;
  11. uscita, isrot:boolean;
  12.  
  13.  
  14. procedure isRotation (x:subtesto;y:subtesto);
  15. var h,k,len:longint;
  16. begin
  17. len:=0; lps[0]:=0; h:=1;
  18. while h< M do
  19. begin
  20. if x[h]=y[len] then
  21. begin
  22. len:=len+1;
  23. lps[h]:=len;
  24. h:=h+1;
  25. end
  26. else
  27. begin
  28. if len<>0 then len:=lps[len-1]
  29. else
  30. begin
  31. lps[h]:=len;
  32. h:=h+1;
  33. end;
  34. end;
  35. end;
  36. h:=0; k:=lps[M-1] ; uscita:=false;
  37. while (k< M) and (h<M) and (uscita=false) do
  38. begin
  39. if y[k]<>x[h] then uscita:=true
  40. else
  41. begin h:=h+1; k:=k+1; end;
  42. end;
  43. if uscita=false then isRot:=true
  44. else isRot:=false;
  45. end;
  46.  
  47.  
  48. begin
  49.  
  50. readln (N,M);
  51. coppie:=0;
  52. for i:=0 to N-1 do begin
  53. for j:=0 to M-1 do read(str[i][j]);
  54. readln; end;
  55.  
  56. for i:=0 to N-2 do
  57. begin
  58. for j:=0 to M-1 do A[j]:=str[i][j];
  59. for z:=i+1 to N-1 do
  60. begin
  61. for j:=0 to M-1 do B[j]:=str[z][j];
  62. isRotation(A,B);
  63. writeln(i,' ',z,' ',isRot);
  64. if isRot=true then coppie:=coppie+1;
  65. end;
  66. end;
  67. for i:=0 to M-1 do write(LPS[i]); writeln;
  68. writeln (coppie);
  69. end.
  70.  
Success #stdin #stdout 0s 5352KB
stdin
4 4
abcd
xbcd
cdab
dabc
stdout
0 1 FALSE
0 2 TRUE
0 3 TRUE
1 2 FALSE
1 3 FALSE
2 3 TRUE
0123
3