grigory51

wave

Mar 31st, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.15 KB | None | 0 0
  1. program wave;
  2. {$APPTYPE CONSOLE}
  3. uses SysUtils;
  4. const n=5;
  5. var a: array [1..n,1..n] of integer;
  6.     x,y: integer;
  7.  
  8. procedure up(x,y: integer); forward;
  9. procedure left(x,y: integer); forward;
  10. procedure right(x,y: integer); forward;
  11. procedure down(x,y: integer); forward;
  12.  
  13. procedure right(x,y: integer);
  14. var count: integer;
  15. begin
  16.  for count:=x+1 to n do
  17.  begin
  18.   if (a[y,count]>a[y,count-1]) or (a[y,count]=0) then a[y,count]:=a[y,count-1]+1
  19.   else break;
  20.   if (a[y-1,count] > a[y,count]) or (a[y-1,count]=0) then up(count,y);
  21.   if (a[y+1,count] > a[y,count]) or (a[y+1,count]=0) then down(count,y);
  22.  end;
  23. end;
  24.  
  25. procedure down(x,y: integer);
  26. var count: integer;
  27. begin
  28.  for count:=y+1 to n do
  29.  begin
  30.   if (a[count,x]>a[count-1,x]) or (a[count,x]=0) then a[count,x]:=a[count-1,x]+1
  31.   else break;
  32.   if (a[count,x-1] > a[count,x]) or (a[count,x-1]=0) then left(x,count);
  33.   if (a[count,x+1] > a[count,x]) or (a[count,x+1]=0) then right(x, count);
  34.  end;
  35. end;
  36.  
  37. procedure up(x,y: integer);
  38. var count: integer;
  39. begin
  40.  for count:=y-1 downto 1 do
  41.  begin
  42.   if (a[count,x]>a[count+1,x]) or (a[count,x]=0) then a[count,x]:=a[count+1,x]+1
  43.   else break;
  44.   if (a[count,x-1] > a[count,x]) or (a[count,x-1]=0) then left(x,count);
  45.   if (a[count,x+1] > a[count,x]) or (a[count,x+1]=0) then right(x, count);
  46.  end;
  47. end;
  48.  
  49. procedure left(x,y: integer);
  50. var count: integer;
  51. begin
  52.  for count:=x-1 downto 1 do
  53.  begin
  54.   if (a[y,count]>a[y,count+1]) or (a[y,count]=0) then a[y,count]:=a[y,count+1]+1
  55.   else break;
  56.   if (a[y-1,count] > a[y,count]) or (a[y-1,count]=0) then up(count,y);
  57.   if (a[y+1,count] > a[y,count]) or (a[y+1,count]=0) then down(count,y);
  58.  end;
  59. end;
  60.  
  61. procedure writing;
  62. var i,j: integer;
  63. begin
  64.  for i:=1 to n do
  65.  begin
  66.   for j:=1 to n do write(a[i,j],' ');
  67.   writeln;
  68.  end;
  69. end;
  70.  
  71. begin
  72.  fillchar(a, sizeof(a),0);
  73.  read(x,y);
  74.  if (x>=1) and (x<=n) and (y>=1) and (y<=n) then
  75.  begin
  76.   while (x<>0) and (y<>0) do
  77.   begin
  78.    a[y,x]:=1;
  79.    up(x,y);
  80.    down(x,y);
  81.    left(x,y);
  82.    right(x,y);
  83.    writing;
  84.    readln(x,y);
  85.    fillchar(a, sizeof(a),0);
  86.   end;
  87.  end
  88.  else
  89.  begin
  90.   write('Invalid Parameter');
  91.   sleep(10000);
  92.  end;
  93. end.
Advertisement
Add Comment
Please, Sign In to add comment