Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.92 KB | None | 0 0
  1.  
  2. const
  3.     ikl = 64;
  4.  
  5. type
  6.     pole = record
  7.         x: integer;
  8.         y: integer;
  9.     end;
  10.  
  11. type
  12.     mas = array[1..ikl]of pole;
  13.  
  14. function obx(tek1: pole; proi: mas; sh: integer): boolean;
  15. var
  16.     i: integer;
  17.     tested: boolean;
  18. begin
  19.     tested := true;
  20.     for i := 1 to sh do
  21.     begin
  22.         if (proi[i].x = tek1.x) and (proi[i].y = tek1.y) then
  23.             tested := false;
  24.     end;
  25.     obx := tested;
  26. end;
  27.  
  28. function shaq(tek, fin: pole; proi: mas; colv, sh: integer): integer;
  29. var
  30.     sum: integer;
  31.     tek1: pole;
  32. begin
  33.     sum := 0;
  34.     if (tek.x = fin.x) and (tek.y = fin.y) then
  35.         sum := 1
  36.     else
  37.     begin
  38.         if colv > 0 then
  39.         begin
  40.             proi[sh] := tek;
  41.             if tek.x + 2 <= 8 then
  42.             begin
  43.                 if tek.y + 1 <= 8 then
  44.                 begin
  45.                     tek1.x := tek.x + 2;
  46.                     tek1.y := tek.y + 1;
  47.                     if obx(tek1, proi, sh) then
  48.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  49.                 end;
  50.                 if tek.y - 1 >= 1 then
  51.                 begin
  52.                     tek1.x := tek.x + 2;
  53.                     tek1.y := tek.y - 1;
  54.                     if obx(tek1, proi, sh) then
  55.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  56.                 end;
  57.             end;
  58.             if tek.x - 2 >= 1 then
  59.             begin
  60.                 if tek.y + 1 <= 8 then
  61.                 begin
  62.                     tek1.x := tek.x - 2;
  63.                     tek1.y := tek.y + 1;
  64.                     if obx(tek1, proi, sh) then
  65.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  66.                 end;
  67.                 if tek.y - 1 >= 1 then
  68.                 begin
  69.                     tek1.x := tek.x - 2;
  70.                     tek1.y := tek.y - 1;
  71.                     if obx(tek1, proi, sh) then
  72.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  73.                 end;
  74.             end;
  75.             if tek.y + 2 <= 8 then
  76.             begin
  77.                 if tek.x + 1 <= 8 then
  78.                 begin
  79.                     tek1.x := tek.x + 1;
  80.                     tek1.y := tek.y + 2;
  81.                     if obx(tek1, proi, sh) then
  82.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  83.                 end;
  84.                 if tek.x - 1 >= 1 then
  85.                 begin
  86.                     tek1.x := tek.x - 1;
  87.                     tek1.y := tek.y + 2;
  88.                     if obx(tek1, proi, sh) then
  89.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  90.                 end;
  91.             end;
  92.             if tek.y - 2 >= 1 then
  93.             begin
  94.                 if tek.x + 1 <= 8 then
  95.                 begin
  96.                     tek1.x := tek.x + 1;
  97.                     tek1.y := tek.y - 2;
  98.                     if obx(tek1, proi, sh) then
  99.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  100.                 end;
  101.                 if tek.x - 1 >= 1 then
  102.                 begin
  103.                     tek1.x := tek.x - 1;
  104.                     tek1.y := tek.y - 2;
  105.                     if obx(tek1, proi, sh) then
  106.                         sum := sum + shaq(tek1, fin, proi, colv - 1, sh + 1);
  107.                 end;
  108.             end;
  109.         end;
  110.     end;
  111.     shaq := sum;
  112. end;
  113.  
  114. var
  115.     proi: mas;
  116.     s, s1, alf: string;
  117.     star, fin: pole;
  118.     colv, colvsha, code: integer;
  119.  
  120. begin
  121.     alf := 'ABCDEFGH';
  122.     readln(s);
  123.     s1 := copy(s, 1, pos(' ', s) - 1);
  124.     delete(s, 1, pos(' ', s));
  125.     star.x := pos(copy(s1, 1, 1), alf);
  126.     val(copy(s1,2,1), star.y, code);
  127.     s1 := copy(s, 1, pos(' ', s) - 1);
  128.     delete(s, 1, pos(' ', s));
  129.     fin.x := pos(copy(s1, 1, 1), alf);
  130.     val(copy(s1,2,1), fin.y, code);
  131.     val(copy(s,1,1), colv, code);
  132.     colvsha := shaq(star, fin, proi, colv, 1);
  133.     writeln(colvsha);
  134. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement