vj p1040题解
简单高精,其他不解释
代码如下:
1 type arra=array[-3..10000]of longint;
2 var a,b,c:arra;
3 m,n,next,l1,l2,l3:longint;
4 procedure init(var m:arra;var lo:longint);
5 var k:array[-4..10000]of char;
6 q:array[-3..10000]of longint;
7 l,i,j,z,p:longint;
8 s:string;
9 begin
10 l:=0;
11 fillchar(m,sizeof(m),0);
12 while not(eoln) do
13 begin
14 inc(l);
15 read(k[l]);
16 end;
17 for i:=-4 to 0 do k[i]:='0';
18 for i:=1 to (l div 3)+1 do
19 begin
20 s:='000';
21 z:=1;
22 for j:=l-i*3+1 to l-(i-1)*3 do
23 begin
24 s[z]:=k[j];
25 inc(z);
26 end;
27 val(s,q[i]);
28 end;
29 readln;
30 lo:=(l div 3)+1;
31 m:=q;
32 end;
33 procedure multiplied(a,b:arra;l1,l2:longint);
34 var i,j:longint;
35 s:string;
36 begin
37 l3:=l1+l2;
38 next:=0;
39 fillchar(c,sizeof(c),0);
40 for i:=1 to l1 do
41 for j:=1 to l2 do
42 begin
43 c[i+j-1]:=a[i]*b[j]+c[i+j-1];
44 if c[i+j-1]>=1000 then
45 begin
46 c[i+j]:=c[i+j]+c[i+j-1] div 1000;
47 c[i+j-1]:=c[i+j-1] mod 1000;
48 if i+j>l3 then inc(l3);
49 end;
50 end;
51 while c[l3]=0 do dec(l3);
52 write(c[l3]);
53 for i:=l3-1 downto 1 do
54 begin
55 str(c[i],s);
56 while length(s)<3 do s:='0'+s;
57 write(s);
58 end;
59 end;
60
61 begin
62 init(a,l1);
63 init(b,l2);
64 multiplied(a,b,l1,l2);
65 end.
2 var a,b,c:arra;
3 m,n,next,l1,l2,l3:longint;
4 procedure init(var m:arra;var lo:longint);
5 var k:array[-4..10000]of char;
6 q:array[-3..10000]of longint;
7 l,i,j,z,p:longint;
8 s:string;
9 begin
10 l:=0;
11 fillchar(m,sizeof(m),0);
12 while not(eoln) do
13 begin
14 inc(l);
15 read(k[l]);
16 end;
17 for i:=-4 to 0 do k[i]:='0';
18 for i:=1 to (l div 3)+1 do
19 begin
20 s:='000';
21 z:=1;
22 for j:=l-i*3+1 to l-(i-1)*3 do
23 begin
24 s[z]:=k[j];
25 inc(z);
26 end;
27 val(s,q[i]);
28 end;
29 readln;
30 lo:=(l div 3)+1;
31 m:=q;
32 end;
33 procedure multiplied(a,b:arra;l1,l2:longint);
34 var i,j:longint;
35 s:string;
36 begin
37 l3:=l1+l2;
38 next:=0;
39 fillchar(c,sizeof(c),0);
40 for i:=1 to l1 do
41 for j:=1 to l2 do
42 begin
43 c[i+j-1]:=a[i]*b[j]+c[i+j-1];
44 if c[i+j-1]>=1000 then
45 begin
46 c[i+j]:=c[i+j]+c[i+j-1] div 1000;
47 c[i+j-1]:=c[i+j-1] mod 1000;
48 if i+j>l3 then inc(l3);
49 end;
50 end;
51 while c[l3]=0 do dec(l3);
52 write(c[l3]);
53 for i:=l3-1 downto 1 do
54 begin
55 str(c[i],s);
56 while length(s)<3 do s:='0'+s;
57 write(s);
58 end;
59 end;
60
61 begin
62 init(a,l1);
63 init(b,l2);
64 multiplied(a,b,l1,l2);
65 end.