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.
#include <iostream>
#include <string>
#include <conio.h>
#define ESC 27
using namespace std;
int main() {
char ch;
int sum = 0;
do {
ch = _getch();
if (ch == ESC) {
cout << "Output of the program:\n" << sum;
putchar('\n');
} else {
cout << ch;
sum += (int)ch;
putchar('\n');
}
} while (ch != ESC);
system("pause");
return 0;
}
Объяснение:
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.