展开全部
//单精度乘高精度的。
program high_hwr;
const
maxn=255;
type
high=array[0..maxn]of integer;
var
a:high;
b,i:longint;
s:ansistring;
function times(a:high;b:longint):high;
var
i,s,g:longint;
begin
g:=0;
for i:=1 to a[0]+4 do begin
s:=a[i]*b+g;
a[i]:=s mod 10000;
g:=s div 10000;
end;
while (a[a[0]]=0)and(a[0]>1) do dec(a[0]);
times:=a;
end;
begin
readln(s);
a[0]:=0;
i:=length(s);
while i>0 do begin
inc(a[0]);
if i>=4 then begin
val(copy(s,i-3,4),a[a[0]]);
delete(s,i-3,4);
dec(i,4);
end else begin
val(s,a[a[0]]);
i:=0;
end;
end;
readln(b);
a:=times(a,b);
write(a[a[0]]);
dec(a[0]);
while a[0]>0 do begin
str(a[a[0]],s);
for i:=1 to 4-length(s) do s:='0'+s;
write(s);
dec(a[0]);
end;
writeln;
end.
program high_hwr;
const
maxn=255;
type
high=array[0..maxn]of integer;
var
a:high;
b,i:longint;
s:ansistring;
function times(a:high;b:longint):high;
var
i,s,g:longint;
begin
g:=0;
for i:=1 to a[0]+4 do begin
s:=a[i]*b+g;
a[i]:=s mod 10000;
g:=s div 10000;
end;
while (a[a[0]]=0)and(a[0]>1) do dec(a[0]);
times:=a;
end;
begin
readln(s);
a[0]:=0;
i:=length(s);
while i>0 do begin
inc(a[0]);
if i>=4 then begin
val(copy(s,i-3,4),a[a[0]]);
delete(s,i-3,4);
dec(i,4);
end else begin
val(s,a[a[0]]);
i:=0;
end;
end;
readln(b);
a:=times(a,b);
write(a[a[0]]);
dec(a[0]);
while a[0]>0 do begin
str(a[a[0]],s);
for i:=1 to 4-length(s) do s:='0'+s;
write(s);
dec(a[0]);
end;
writeln;
end.
展开全部
唉,真是笨蛋,何必如此的大费周折
var a,b,c:longint;
begin
readln(a,b);
c:=a*b;
if c>9999 then begin
c:=c mod 10000;
writeln(c);
end
else begin
writeln(c);
end;
end.
var a,b,c:longint;
begin
readln(a,b);
c:=a*b;
if c>9999 then begin
c:=c mod 10000;
writeln(c);
end
else begin
writeln(c);
end;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要高精度乘高精度吗?带优化的(4位一组)
var
a, b, c : array[0..1000] of word;
procedure init;
var
s : string;
ok, i, j : integer;
begin
assign(input,'f:\input.txt');
reset(input);
readln(s);
a[0]:=length(s);
for i:=1 to a[0] do
val(s[a[0]-i+1],a[i],ok);
readln(s);
b[0]:=length(s);
for i:=1 to b[0] do
val(s[b[0]-i+1],b[i],ok);
close(input);
end;
procedure highmul;
var i, j, k : integer;
begin
c[0]:=a[0]+b[0]+1;
for i:=1 to a[0] do
for j:=1 to b[0] do
begin
inc(c[i+j-1], a[i]*b[j] mod 10);
c[i+j]:=c[i+j]+(a[i]*b[j] div 10)
+(c[i+j-1] div 10);
c[i+j-1]:=c[i+j-1] mod 10;
end;
end;
procedure print;
var i: integer;
begin
while c[c[0]]=0 do dec(c[0]);
for i:=c[0] downto 1 do write(c[i]);
writeln;
end;
begin{main}
init;
highmul;
print;
end.
var
a, b, c : array[0..1000] of word;
procedure init;
var
s : string;
ok, i, j : integer;
begin
assign(input,'f:\input.txt');
reset(input);
readln(s);
a[0]:=length(s);
for i:=1 to a[0] do
val(s[a[0]-i+1],a[i],ok);
readln(s);
b[0]:=length(s);
for i:=1 to b[0] do
val(s[b[0]-i+1],b[i],ok);
close(input);
end;
procedure highmul;
var i, j, k : integer;
begin
c[0]:=a[0]+b[0]+1;
for i:=1 to a[0] do
for j:=1 to b[0] do
begin
inc(c[i+j-1], a[i]*b[j] mod 10);
c[i+j]:=c[i+j]+(a[i]*b[j] div 10)
+(c[i+j-1] div 10);
c[i+j-1]:=c[i+j-1] mod 10;
end;
end;
procedure print;
var i: integer;
begin
while c[c[0]]=0 do dec(c[0]);
for i:=c[0] downto 1 do write(c[i]);
writeln;
end;
begin{main}
init;
highmul;
print;
end.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询