unit z13; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; const c1=15; c2=12.5; type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure NahTo4ek; procedure Dopusk; procedure Maximum; private { Private declarations } public { Public declarations } end; var Form1: TForm1; dann:array [1..2,1..4] of real; to4ki: array [1..2,1..6] of real; temp:string; /////////////////////////////////////////////////////////// implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i,j:byte; begin try for i:=1 to 2 do for j:=1 to 4 do begin dann[i,j]:=StrToInt(StringGrid1.Cells[i,j]); end; except on eConvertError do begin showmessage('Введены не корректные'+#13#10+'начальные данные.'); exit; end; end; for i:=1 to 2 do for j:=1 to 4 do begin if dann[i,j]<>0 then dann[i,j]:=100/dann[i,j]; end; NahTo4ek; Dopusk; Maximum; end; procedure TForm1.FormCreate(Sender: TObject); var i,j:byte; begin StringGrid1.Cells[1,0]:='Кухни А'; StringGrid1.Cells[2,0]:='Кухни В'; StringGrid1.Cells[0,1]:='Штамповка'; StringGrid1.Cells[0,2]:='Отделка'; StringGrid1.Cells[0,3]:='Сборка А'; StringGrid1.Cells[0,4]:='Сборка B'; for i:=1 to 2 do for j:=1 to 4 do StringGrid1.Cells[i,j]:='0'; end; procedure TForm1.NahTo4ek; var i,y,n:byte; i1,i2,y1,y2,x1,x2:real; begin n:=1; for i:=1 to 3 do for y:=i+1 to 4 do begin i1:=dann[1,i]; i2:=dann[2,i]; y1:=dann[1,y]; y2:=dann[2,y]; if (i1<>0) and (i2<>0) and (y1<>0) and (y2<>0) then begin x2:=100*(1-i1/y1)/(i2-i1*y2/y1); x1:=(100-i2*x2)/i1; end else begin if (i1=0) and (y2=0) then begin x1:=100/y1; x2:=100/i2; end else begin if (i2=0) and (y1=0) then begin x1:=100/i1; x2:=100/y2; end else begin if i1=0 then begin x2:=100/i2; x1:=(100-y2*x2)/y1; end else begin if i2=0 then begin x1:=100/i1; x2:=(100-y1*x1)/y2; end else begin if y1=0 then begin x2:=100/y2; x1:=(100-i2*x2)/i1; end else begin if y2=0 then begin x1:=100/y1; x2:=(100-i1*x1)/i2; end; end; end; end; end; end; end; to4ki[1,n]:=x1; to4ki[2,n]:=x2; inc(n); end; end; procedure TForm1.Dopusk; var i,y:byte; begin for i:=1 to 6 do begin to4ki[1,i]:=Trunc(to4ki[1,i]); to4ki[2,i]:=Trunc(to4ki[2,i]); end; for i:=1 to 6 do if (to4ki[1,i]<0) or (to4ki[2,i]<0) then begin to4ki[1,i]:=0; to4ki[2,i]:=0; end else begin for y:=1 to 4 do if (dann[1,y]*to4ki[1,i]+dann[2,y]*to4ki[2,i])>100 then begin to4ki[1,i]:=0; to4ki[2,i]:=0; end; end; end; procedure TForm1.Maximum; var m,i:byte; mm:real; begin mm:=0; for i:=1 to 6 do if (c1*to4ki[1,i]+c2*to4ki[2,i])>mm then begin mm:=c1*to4ki[1,i]+c2*to4ki[2,i]; m:=i; end; showmessage(floattostr(to4ki[1,m])+' '+floattostr(to4ki[2,m])) end; end.