uses
Math;
const
M =
10
;
var
C, P, X:
array
[
0..
M]
of
integer
;
function
ds(C,P:
array
of
integer
):
boolean
;
var
i, j:
integer
;
begin
Result:=
true
;
for
i:=
0
to
Length(C)-
1
do
for
j:=
0
to
Length(P)-
1
do
if
C[i] = P[j]
then
Result:=
false
;
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
var
i:
integer
;
begin
for
i:=
0
to
M-
1
do
begin
C[i]:= Random(
100
);
P[i]:= Random(
100
);
end
;
StringGrid1
.
ColCount:= M;
for
i:=
0
to
StringGrid1
.
ColCount-
1
do
with
StringGrid1
do
begin
Cells[i,
0
]:=
'C'
+ IntToStr(i+
1
);
Cells[i,
1
]:= IntToStr(C[i]);
Cells[i,
3
]:=
'P'
+ IntToStr(i+
1
);
Cells[i,
4
]:= IntToStr(P[i]);
Cells[i,
6
]:=
'X'
+ IntToStr(i+
1
);
end
;
end
;
procedure
TForm1
.
FormCreate(Sender: TObject);
begin
Randomize;
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
var
i:
integer
;
begin
if
ds(C,P)
then
for
i:=
0
to
M-
1
do
X[i]:= max(C[i], P[i]);
for
i:=
0
to
StringGrid1
.
ColCount-
1
do
StringGrid1
.
Cells[i,
7
]:= IntToStr(X[i]);
end
;