Dennnhhhickk

Untitled

Oct 8th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. program Project5;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. const
  9. MAXIN = 10000;
  10.  
  11. var
  12. n, i, j, k: integer;
  13. a: array [0..MAXIN, 0..MAXIN] of integer;
  14.  
  15. procedure wiwod();
  16. var
  17. i, j: integer;
  18. time: array [0..MAXIN] of integer;
  19. begin
  20. for i := 1 to n do
  21. time[i] := 0;
  22.  
  23. for i := 1 to n do
  24. for j := 1 to n do
  25. inc(time[a[i][j]]);
  26.  
  27. //for i := 1 to n do
  28. //if (time[i] <> n) then
  29. //exit;
  30.  
  31. for i := 1 to n do
  32. begin
  33. for j := 1 to n - 1 do
  34. write(a[i][j], ' ');
  35. writeln(a[i][n]);
  36. end;
  37. readln;
  38. readln;
  39. halt(0);
  40. end;
  41.  
  42. procedure rec(x, y: integer);
  43. var
  44. i, j: integer;
  45. time: array [0..MAXIN] of integer;
  46. begin
  47. inc(k);
  48. if (k = 1001) then
  49. wiwod;
  50. for i := 1 to n do
  51. time[i] := i;
  52.  
  53. for i := 1 to n do
  54. begin
  55. time[a[x][i]] := 0;
  56. time[a[i][y]] := 0;
  57. end;
  58.  
  59. //writeln(' ', a[x][y], ' ',x, ' ',y);
  60. if (a[x][y] = 0) then
  61. begin
  62. for i := 1 to n do
  63. if (time[i] <> 0) then
  64. begin
  65. a[x][y] := time[i];
  66. if (x = n) and (y = n) then
  67. wiwod()
  68. else
  69. if (y = n) then
  70. rec(x + 1, 1)
  71. else
  72. rec(x, y + 1);
  73. end
  74. else
  75. begin
  76.  
  77. end;
  78. end
  79. else
  80. if (x = n) and (y = n) then
  81. wiwod()
  82. else
  83. if (y = n) then
  84. rec(x + 1, 1)
  85. else
  86. rec(x, y + 1);
  87. a[x][y] := 0;
  88. end;
  89.  
  90. begin
  91. //assign(output,'out.txt');
  92. //rewrite(output);
  93. readln(n);
  94. k := 0;
  95.  
  96. for i := 1 to n do
  97. for j := 1 to n do
  98. read(a[i][j]);
  99.  
  100. rec(1, 1);
  101. //close(output);
  102. readln;
  103. readln;
  104. end.
Advertisement
Add Comment
Please, Sign In to add comment