Program Task; Const N = 499; M = 1; Var A: Array [1..N, 1..N] of Boolean; i, j, x, y, t: Integer; b: Boolean; Begin Randomize; While i < M Do Begin x := Random(N) + 1; y := Random(N) + 1; If A[x, y] = False Then Begin A[x, y] := True; i := i + 1; End; End; While b = False Do Begin b := True; For i := 1 To N Do For j := 1 To N Do Begin If A[i, j] = True Then Begin If (i + 1) <= N Then A[i + 1, j] := True; If (i - 1) > 0 Then A[i - 1, j] := True; If(j + 1) <= N Then A[i, j + 1] := True; If (j -1) > 0 Then A[i, j - 1] := True; End; End; For i := 1 To N Do For j := 1 To N Do If A[i, j] = False Then b := False; t := t + 1; End; WriteLn(t); ReadLn; End.
2. Популярное до сих пор в школах решение на TurboPascal 7.01 (1983г.)
uses Crt; const nn=100; var i,n,min:integer; a:array[1..nn] of integer; begin ClrScr; Randomize; Write('n='); Read(n); min:=100; for i:=1 to n do begin a[i]:=Random(101)-50; Write(a[i],' '); if a[i]<min then min:=a[i] end; Writeln; for i:=1 to n do if a[i]<0 then a[i]:=a[i]*min; for i:=1 to n do Write(a[i],' '); Writeln; ReadKey end.
Const N = 499; M = 1;
Var A: Array [1..N, 1..N] of Boolean;
i, j, x, y, t: Integer;
b: Boolean;
Begin
Randomize;
While i < M Do
Begin
x := Random(N) + 1;
y := Random(N) + 1;
If A[x, y] = False Then
Begin
A[x, y] := True;
i := i + 1;
End;
End;
While b = False Do
Begin
b := True;
For i := 1 To N Do
For j := 1 To N Do
Begin
If A[i, j] = True Then
Begin
If (i + 1) <= N Then
A[i + 1, j] := True;
If (i - 1) > 0 Then
A[i - 1, j] := True;
If(j + 1) <= N Then
A[i, j + 1] := True;
If (j -1) > 0 Then
A[i, j - 1] := True;
End;
End;
For i := 1 To N Do
For j := 1 To N Do
If A[i, j] = False Then
b := False;
t := t + 1;
End;
WriteLn(t);
ReadLn;
End.
// PascalABC.NET 3.2, сборка 1437 от 03.05.2017
// Внимание! Если программа не работает, обновите версию!
begin
var a:=ArrRandom(ReadInteger('n='),-50,50); a.Println;
var min:=a.Min;
a.Transform(x->x<0?x*min:x); a.Println
end.
Пример
n= 15
-34 7 0 -48 4 42 35 14 -47 6 -29 43 46 40 -18
1632 7 0 2304 4 42 35 14 2256 6 1392 43 46 40 864
2. Популярное до сих пор в школах решение на TurboPascal 7.01 (1983г.)
uses Crt;
const
nn=100;
var
i,n,min:integer;
a:array[1..nn] of integer;
begin
ClrScr;
Randomize;
Write('n='); Read(n);
min:=100;
for i:=1 to n do begin
a[i]:=Random(101)-50;
Write(a[i],' ');
if a[i]<min then min:=a[i]
end;
Writeln;
for i:=1 to n do
if a[i]<0 then a[i]:=a[i]*min;
for i:=1 to n do
Write(a[i],' ');
Writeln;
ReadKey
end.