高精度乘单精度(1位数) 程序如下: programHighPrecision3_Multiply1;
const
fn_inp='hp3.inp';
fn_out='hp3.out';
maxlen=100; { max length of the number }
type
hp=record
len:integer; { length of the number }
s:array[1..maxlen] of integer
{ s[1] is the lowest position
s[len] is the highest position}
end;
var
x,y:hp; { x:input hp ; y ![](static/image/smiley/default/shocked.gif) utput }
z:integer; { z:input lp } procedure PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s);
end; procedure init;
var
st:string;
i:integer;
begin
assign(input,fn_inp);
reset(input);
readln(st);
x.len:=length(st);
for i:=1 to x.len do { change string to HP }
x.s:=ord(st[x.len+1-i])-ord('0');
readln(z);
close(input);
end; procedure Multiply(a:hp;b:integer;var c:hp); { c:=a*b }
var i,len:integer;
begin
fillchar(c,sizeof(c),0);
len:=a.len;
for i:=1 to len do
begin
inc(c.s,a.s*b);
inc(c.s[i+1],c.s div 10);
c.s:=c.s mod 10;
end;
inc(len);
while(c.s[len]>=10) do
begin
inc(c.s[len+1],c.s[len] div 10);
c.s[len]=c.s[len] mod 10;
inc(len);
end;
while(len>1) and (c.s[len]=0) do dec(len);
c.len:=len;
end; procedure main;
begin
Multiply(x,z,y);
end; procedure out;
begin
assign(output,fn_out);
rewrite(output);
PrintHP(y);
writeln;
close(output);
end; begin
init;
main;
out;
end.
|