fork download
  1. program casino;
  2. const lung=1000000;
  3. var N,M,i,z,coppie:qword;
  4. A,B: AnsiString;
  5. isRot,uscita :boolean;
  6. S:array[0..lung] of AnsiString;
  7.  
  8. procedure isRotation (var x: AnsiString; var y: AnsiString);
  9. var h,k,len:qword;
  10. reset :boolean;
  11. begin
  12. h:=0; k:=0; len:=0;
  13. reset:=false; uscita:=false;
  14. while uscita=false do
  15. begin
  16. if (h=2*M-1) and (len<>M) then begin uscita:=true; isRot:=false;end
  17. else
  18. begin
  19. if len=M then begin isRot:=true; uscita:=true; end
  20. else
  21. begin
  22. if x[h mod M+1]=y[k mod M+1] then
  23. begin
  24. if reset =true then reset:=false;
  25. h:=h+1;
  26. k:=k+1;
  27. len:=len+1;
  28. end
  29. else begin if reset=true then begin reset:=false; h:=h+1; end
  30. else
  31. begin
  32. reset:=true;
  33. k:=0;
  34. len:=0;
  35. end;
  36. end;
  37. end;
  38. end;
  39. end;
  40. end;
  41.  
  42.  
  43. begin
  44.  
  45. readln (N,M);
  46. for i:=0 to N-1 do readln(S[i]);
  47. coppie:=0;
  48. i:=0;
  49. while i<N-1 do
  50. begin
  51. A:=S[i];
  52. z:=i+1;
  53. while z<N do
  54. begin
  55. B:=S[z];
  56. isRot:=false;
  57. isRotation(A,B);
  58. if isRot=true then coppie:=coppie+1;
  59. z:=z+1;
  60. end;
  61. i:=i+1;
  62. end;
  63. writeln (coppie);
  64. end.
  65.  
Success #stdin #stdout 0.01s 5456KB
stdin
2 6
adaadx
aadxad
stdout
1