⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 大数项乘法 譬如1234567892345678*1234567891223343. 采用数组的方式来解决存储空间不够的问题!
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  const max=2000;
var
  Form1: TForm1;
  a,b,c:array[1..max]of longint;
  i,j,k,l,m,n,s,t,l1,l2:longint;
  ch:char;

implementation

{$R *.dfm}
procedure main;
var
  g:longint;
  i,k:integer;
begin
  for k:=max downto max-l1 do
  begin
    g:=0;
    for i:=max downto max-l2 do
    begin
      inc(c[k-max+i],a[k]*b[i]+g);
      g:=c[k-max+i] div 10;
      c[k-max+i]:=c[k-max+i] mod 10;
    end;
  end;
end;

procedure print;
var
 i,j:integer;
begin
  for j:=max-l1-l2-1 to max do if c[j]<>0 then break;
  for i:=j to max do write(c[i]);
  writeln;
end;
procedure init;
begin
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  fillchar(c,sizeof(c),0);
  l1:=0; l2:=0;
  repeat
    read(ch);
    inc(l1);
    a[l1]:=ord(ch)-ord('0');
  until eoln;
  readln;
  repeat
    read(ch);
    inc(l2);
    b[l2]:=ord(ch)-ord('0');
  until eoln;
  readln;
  for i:=l1 downto 1 do
    begin
      a[max-l1+i]:=a[i];
      a[i]:=0;
    end;
  for i:=l2 downto 1 do
    begin
      b[max-l2+i]:=b[i];
      b[i]:=0;
    end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
 tem1,tem2,tem3,tem4,tem5:string;
 k:integer;
begin
  //assign(input,'temp.in');
  tem1:='8493039506173324807160493827159604950500000000000750718568049382715954277743159488951453963381892878888901194951747996642855215129178581221743395022222';
  tem2:='27160493582406618015142512790123456785679011972032895718901222138452167907071622963277961784902110114539831529571734427654300630324329155435857022222218728367';
  tem3:='88800000000000000000000000000888896000000000000000000000777777777777787089911385503679192421758481657025577257136144011706357';
  tem4:='1014089263815530924514073226436944488917472839542172887031850118749379782525678441835126904938061744691502330856677716851851852096327900885';
  tem5:='300326172317851372726914752389753329030187645856784564831980140901550615592070833136047957840096502418518117098765432038886985777783765480088888888';
  k:=length(tem1)+length(tem2)+length(tem3)+length(tem4)+length(tem5);

  showmessage(inttostr(k));
  reset(input);
  while not seekeof do
  begin
    init;
    main;
    print;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -