Смекни!
smekni.com

Операции многократной точности операции с длинными числами (стр. 2 из 2)

else sislo:=false;

end;

procedure poisk(z:integer);

var

i,k,j,m,k2,zz:integer;

tmp:string;

zn:char;

begin

{snachala ubiraem skobki, potom *, potom /, potom +, potom -}

k:=0;

for i:=1 to mas[z].dl-1 do

if mas[z].lin[i]='(' then k:=k+1;

if k>0 then begin

k2:=0;

for i:=1 to mas[z].dl-1 do begin

if mas[z].lin[i]='(' then k2:=k2+1;

if k2=k then begin

if mas[z].lin[i+2]=')' then begin

mas[z].lin[i]:=mas[z].lin[i+1];

for m:=i+1 to mas[z].dl-2 do mas[z].lin[m]:=mas[z].lin[m+2];

mas[z].dl:=mas[z].dl-2;

poisk(z);

exit;

end

else begin

zz:=i+1;

while mas[z].lin[zz]<>')' do begin

if ((mas[z].lin[zz]='*')or(mas[z].lin[zz]='/')) then begin

if po_ch_num(mas[z].lin[zz-1],tmp) then mas[z].lin[zz-1]:=tmp;

if po_ch_num(mas[z].lin[zz+1],tmp) then mas[z].lin[zz+1]:=tmp;

if (((sislo(mas[z].lin[zz-1][1])))and(sislo(mas[z].lin[zz+1][1]))) then begin

zn:=mas[z].lin[zz][1];

if zn='*' then mas[z].lin[zz-1]:=umnozen(mas[z].lin[zz-1],mas[z].lin[zz+1])

else mas[z].lin[zz-1]:=delen(mas[z].lin[zz-1],mas[z].lin[zz+1]);

for m:=zz to mas[z].dl-2 do mas[z].lin[m]:=mas[z].lin[m+2];

mas[z].dl:=mas[z].dl-2;

poisk(z);

exit;

end;

end;

zz:=zz+1;

end;

//////// {snachala / i *, potom + i -}

zz:=i+1;

while mas[z].lin[zz]<>')' do begin

if ((mas[z].lin[zz]='+')or(mas[z].lin[zz]='-')) then begin

if po_ch_num(mas[z].lin[zz-1],tmp) then mas[z].lin[zz-1]:=tmp;

if po_ch_num(mas[z].lin[zz+1],tmp) then mas[z].lin[zz+1]:=tmp;

if ((sislo(mas[z].lin[zz-1][1]))and(sislo(mas[z].lin[zz+1][1]))) then begin

zn:=mas[z].lin[zz][1];

if zn='+' then mas[z].lin[zz-1]:=form1.sum(mas[z].lin[zz-1],mas[z].lin[zz+1])

else mas[z].lin[zz-1]:=form1.minus(mas[z].lin[zz-1],mas[z].lin[zz+1]);

for m:=zz to mas[z].dl-2 do mas[z].lin[m]:=mas[z].lin[m+2];

mas[z].dl:=mas[z].dl-2;

poisk(z);

exit;

end;

end;

zz:=zz+1;

end;

////////

end;

end;

end;

end

else begin {esli skobok net}

for zz:=1 to mas[z].dl-1 do begin if ((mas[z].lin[zz]='*')or(mas[z].lin[zz]='/')) then begin

if po_ch_num(mas[z].lin[zz-1],tmp) then mas[z].lin[zz-1]:=tmp;

if po_ch_num(mas[z].lin[zz+1],tmp) then mas[z].lin[zz+1]:=tmp;

if ((sislo(mas[z].lin[zz-1][1]))and(sislo(mas[z].lin[zz+1][1]))) then begin

zn:=mas[z].lin[zz][1];

if zn='*' then mas[z].lin[zz-1]:=umnozen(mas[z].lin[zz-1],mas[z].lin[zz+1])

else mas[z].lin[zz-1]:=delen(mas[z].lin[zz-1],mas[z].lin[zz+1]);

for m:=zz to mas[z].dl-2 do mas[z].lin[m]:=mas[z].lin[m+2];

mas[z].dl:=mas[z].dl-2;

poisk(z);

exit;

end;

end;

end;

for zz:=1 to mas[z].dl-1 do begin

////////

if ((mas[z].lin[zz]='+')or(mas[z].lin[zz]='-')) then begin

if po_ch_num(mas[z].lin[zz-1],tmp) then mas[z].lin[zz-1]:=tmp;

if po_ch_num(mas[z].lin[zz+1],tmp) then mas[z].lin[zz+1]:=tmp;

if ((sislo(mas[z].lin[zz-1][1]))and(sislo(mas[z].lin[zz+1][1]))) then begin

zn:=mas[z].lin[zz][1];

if zn='+' then mas[z].lin[zz-1]:=form1.sum(mas[z].lin[zz-1],mas[z].lin[zz+1])

else mas[z].lin[zz-1]:=form1.minus(mas[z].lin[zz-1],mas[z].lin[zz+1]);

for m:=zz to mas[z].dl-2 do mas[z].lin[m]:=mas[z].lin[m+2];

mas[z].dl:=mas[z].dl-2;

poisk(z);

exit;

end;

end;

///////

end;

end;

end;

procedure vivod;

var

i:integer;

begin

form1.Memo3.Clear;

for i:=1 to y do

if mas[i].dl=4 then begin

form1.Memo3.Lines.Add(mas[i].lin[1]+'='+mas[i].lin[3]);

end;

end;

procedure TForm1.Button1Click(Sender: TObject);

var

i,j:integer;

begin

zapolnenie;

for j:=1 to y do

for i:=1 to y do poisk(i);

vivod;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

messagedlg('Îïåðàöèè ìíîãîêðàòíîé òî÷íîñòè',mtinformation,[mbok],0);

end;

end.