萬進製高精度乘法

2021-05-27 03:24:47 字數 1672 閱讀 9470

program hpm;

type

arr=array [1..1000] of longint;

var a,b,c:arr;

lena,lenb,len1,len2,t1,t2:longint;

procedure init;

var s,temp:ansistring;

i:longint;

begin

readln(s);

lena:=length(s);

len1:=lena div 4;

t1:=lena-len1*4;

for i:=1 to len1 do

begin

temp:=copy(s,lena-4*i+1,4);

val(temp,a[i]);

end;

temp:=copy(s,1,t1);

if temp<>'' then

begin

inc(len1);

val(temp,a[len1]);

end;

readln(s);

lenb:=length(s);

len2:=lenb div 4;

t2:=lenb-len2*4;

for i:=1 to len2 do

begin

temp:=copy(s,lenb-4*i+1,4);

val(temp,b[i]);

end;

temp:=copy(s,1,t2);

if temp<>'' then

begin

inc(len2);

val(temp,b[len2]);

end;

end;

procedure mult;

var i,j,len,x:longint;

begin

for i:=1 to len1 do

begin

x:=0;

for j:=1 to len2 do

begin

x:=a[i]*b[j]+x div 10000+c[i+j-1];

c[i+j-1]:=x mod 10000;

end;

c[i+j]:=x div 10000;

end;

len:=len1+len2;

while (c[len]=0) and (len>1) do dec(len);

for i:=len downto 1 do

begin

if i<>len then

begin

if c[i]<1000 then write(0);

if c[i]<100 then write(0);

if c[i]<10 then write(0);

end;

write(c[i]);

end;

end;

begin

assign(input,'hpm.in'); reset(input);

assign(output,'hpm.out'); rewrite(output);

init;

mult;

close(input); close(output);

end.

全能萬進製高精度模板

include include include include include include using namespace std typedef long long llong const int size 50000 const int base 10000 高精度數字中每乙個元素表示數字的...

高精度減法,高精度乘法

高精度減法 oj資料偏弱如果新增乙個101 2就錯了,下面這一步是為了防止錯誤的 if a aa 0 可能出現第一位的1被借走的的情況,所以加乙個while找第乙個不是0的 while c i 0 i include include include include include include u...

高精度乘法

問題描述 給你兩個正整數a,b,計算它們的乘積。輸入格式 第一行乙個正整數a 第二行乙個正整數b 輸出格式 一行,表示a b 樣例輸入 111222333444555666777888999 999888777666555444333222111 樣例輸出 提示 a,b分別不超過100000位 ff...