RSS    

   Реферат: Операции многократной точности (операции с длинными числами)

  while ((c[1]='0')and(length(c)>1)) do c:=copy(c,2,300);

  if pom then c:='-'+c;

  minus:=c;

end;

function umn(a:integer;var xx:string):string;

var

  i,ost,tmp,dl:integer;

  str:string;

begin

ost:=0;

str:='';

dl:=length(xx);

for i:=dl downto 1 do begin

  tmp:=a*strtoint(xx[i])+ost;

  if tmp>9 then begin

    str:=inttostr((tmp mod 10))+str;

    ost:=tmp div 10;

    if i=1 then str:=inttostr(ost)+str;

  end

  else begin

    str:=inttostr(tmp)+str;

    ost:=0;

  end;

end;

umn:=str;

end;

function umnozen(a,b:string):string;

var

  k,i:integer;

  tmp,c,r:string;

  bol:boolean;

begin

    bol:=false;

    if ((b[1]='-') and (a[1]<>'-')) then begin

      bol:=true;  b:=copy(b,2,300);

    end;

    if ((a[1]='-') and (b[1]<>'-')) then begin

      bol:=true;  a:=copy(a,2,300);

    end;

    if ((b[1]='-') and (a[1]='-')) then begin

      a:=copy(a,2,300); b:=copy(b,2,300)

    end;

    if ((a='0')or(b='0')) then begin

      umnozen:='0'; exit;

    end;

  k:=length(b);

  c:='0';   tmp:='';

  for i:=k downto 1 do begin

    r:=umn(strtoint(b[i]),a);

    r:=r+tmp;

    tmp:=tmp+'0';

    c:=form1.sum(c,r);

  end;

  if bol then c:='-'+c;

  umnozen:=c;

end;

function sravnenie(a,b:string):shortint;

{  если а>b, то сравнение=1

   если а<b, то сравнение=-1

   если а<b, то сравнение=0}

var

  la,lb,i:integer;

begin

  la:=length(a);  lb:=length(b);

  if a[1]='-' then begin

    if b[1]='-' then sravnenie:=sravnenie(b,a)

    else sravnenie:=-1;

  exit;

  end;

  if b[1]='-' then begin

    if a[1]='-' then sravnenie:=sravnenie(b,a)

    else sravnenie:=1;

  exit;

  end;

  if lb>la then sravnenie:=-1;

  if lb<la then sravnenie:=1;;

  if la=lb then begin

  for i:=1 to la do begin

    if a[i]>b[i] then begin

      sravnenie:=1;

      exit;

    end;

    if a[i]<b[i] then begin

      sravnenie:=-1;

      exit;

    end;

  end;

  sravnenie:=0;

  end;

end;

function del2(str:string):string;

var

  ost,i:integer;

  dr:string;

begin

  ost:=0;

  dr:='';

  for i:=1 to length(str) do begin

    dr:=dr+inttostr((strtoint(str[i])+ost*10) div 2);

    ost:=((strtoint(str[i])+ost*10) mod 2);

  end;

  if dr[1]='0' then dr:=copy(dr,2,300);

  del2:=dr;

end;

function delen(a,b:string):string;

{delen=round(a/b)}

var

  bol,zzz:boolean;

  pr,tmp,lev,prav,rab:string;

begin

    if b='0' then begin

      showmessage('Íà íîëü äåëèòü íåëüçÿ!');

      delen:='';

      exit;

    end;

    zzz:=false;

    if ((b[1]='-') and (a[1]<>'-')) then begin

      zzz:=true;  b:=copy(b,2,300);

    end;

    if ((a[1]='-') and (b[1]<>'-')) then begin

      zzz:=true;  a:=copy(a,2,300);

    end;

    if ((b[1]='-') and (a[1]='-')) then begin

      a:=copy(a,2,300); b:=copy(b,2,300)

    end;

  bol:=true;

  lev:='0';    prav:=a;   pr:='0'; rab:=a;

  if b<>'1' then

  while (bol) do begin

    tmp:=form1.minus(a,pr);

    if tmp[1]='-' then tmp:=copy(tmp,2,300);

    if (sravnenie(tmp,del2(b))<>1) then break;//bol:=false;

    tmp:=form1.minus(prav,lev); rab:='';

    rab:=form1.sum(lev,del2(tmp));

    pr:=umnozen(b,rab);

    if sravnenie(a,pr)=1 then begin

      lev:=rab;

    end

    else begin

      prav:=rab;

    end;

  end;

      if zzz then rab:='-'+rab;

      delen:=rab;

      if ((rab='-')or(rab=''))then delen:='0';

end;

function po_ch_num(ch:string;var znach:string):boolean;

var

  bol:boolean;

  i:integer;

begin

  bol:=false;

  for i:=1 to y do begin

    if ((mas[i].dl=4)and(mas[i].lin[1]=ch)) then begin

      bol:=true;

      znach:=mas[i].lin[3];

    end;

  end;

po_ch_num:=bol;

end;

function sislo(ch:char):boolean;

begin

  if ((ch>='0')and(ch<='9')or(ch='-')) then sislo:=true

  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.


Страницы: 1, 2


Новости


Быстрый поиск

Группа вКонтакте: новости

Пока нет

Новости в Twitter и Facebook

                   

Новости

Обратная связь

Поиск
Обратная связь
Реклама и размещение статей на сайте
© 2010.