Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program wave;
- {$APPTYPE CONSOLE}
- uses SysUtils;
- const n=5;
- var a: array [1..n,1..n] of integer;
- x,y: integer;
- procedure up(x,y: integer); forward;
- procedure left(x,y: integer); forward;
- procedure right(x,y: integer); forward;
- procedure down(x,y: integer); forward;
- procedure right(x,y: integer);
- var count: integer;
- begin
- for count:=x+1 to n do
- begin
- if (a[y,count]>a[y,count-1]) or (a[y,count]=0) then a[y,count]:=a[y,count-1]+1
- else break;
- if (a[y-1,count] > a[y,count]) or (a[y-1,count]=0) then up(count,y);
- if (a[y+1,count] > a[y,count]) or (a[y+1,count]=0) then down(count,y);
- end;
- end;
- procedure down(x,y: integer);
- var count: integer;
- begin
- for count:=y+1 to n do
- begin
- if (a[count,x]>a[count-1,x]) or (a[count,x]=0) then a[count,x]:=a[count-1,x]+1
- else break;
- if (a[count,x-1] > a[count,x]) or (a[count,x-1]=0) then left(x,count);
- if (a[count,x+1] > a[count,x]) or (a[count,x+1]=0) then right(x, count);
- end;
- end;
- procedure up(x,y: integer);
- var count: integer;
- begin
- for count:=y-1 downto 1 do
- begin
- if (a[count,x]>a[count+1,x]) or (a[count,x]=0) then a[count,x]:=a[count+1,x]+1
- else break;
- if (a[count,x-1] > a[count,x]) or (a[count,x-1]=0) then left(x,count);
- if (a[count,x+1] > a[count,x]) or (a[count,x+1]=0) then right(x, count);
- end;
- end;
- procedure left(x,y: integer);
- var count: integer;
- begin
- for count:=x-1 downto 1 do
- begin
- if (a[y,count]>a[y,count+1]) or (a[y,count]=0) then a[y,count]:=a[y,count+1]+1
- else break;
- if (a[y-1,count] > a[y,count]) or (a[y-1,count]=0) then up(count,y);
- if (a[y+1,count] > a[y,count]) or (a[y+1,count]=0) then down(count,y);
- end;
- end;
- procedure writing;
- var i,j: integer;
- begin
- for i:=1 to n do
- begin
- for j:=1 to n do write(a[i,j],' ');
- writeln;
- end;
- end;
- begin
- fillchar(a, sizeof(a),0);
- read(x,y);
- if (x>=1) and (x<=n) and (y>=1) and (y<=n) then
- begin
- while (x<>0) and (y<>0) do
- begin
- a[y,x]:=1;
- up(x,y);
- down(x,y);
- left(x,y);
- right(x,y);
- writing;
- readln(x,y);
- fillchar(a, sizeof(a),0);
- end;
- end
- else
- begin
- write('Invalid Parameter');
- sleep(10000);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment