2 arr
=array [0..80,0..2] of longint;
6 i
,j
,lena
,lenb
,lenc
,lenp
:longint;
9 function len(a
:longint):string;
16 if s
='1' then exit('');
17 for i
:=1 to length(s
) do s
[i
]:=' ';
21 function getsum(st
:string; var k
:longint):longint;
24 while (k
<=length(st
)) and (st
[k
] in ['0'..'9']) do begin getsum
:=getsum
*10+ord(st
[k
])-ord('0'); inc(k
); end;
27 procedure trans(st
:string; var p
:arr
);
30 q
:array [0..80] of string;
35 for i
:=1 to 80 do q
[i
]:='';
37 for j
:=1 to length(st
) do
39 if (st
[j
]='+') or (st
[j
]='-') then inc(i
);
46 if q
[j
][1]='-' then p
[j
,0]:=-1 else p
[j
,0]:=1;
47 k
:=2; t
:=getsum(q
[j
],k
);
48 if t
<>0 then p
[j
,0]:=p
[j
,0]*t
;
49 if k
>length(q
[j
]) then continue
;
50 if q
[j
][k
]='x' then begin inc(k
); t
:=getsum(q
[j
],k
); if t
=0 then t
:=1; p
[j
,1]:=t
; end
51 else if q
[j
][k
]='y' then begin inc(k
); t
:=getsum(q
[j
],k
); if t
=0 then t
:=1; p
[j
,2]:=t
; end;
52 if k
<=length(q
[j
]) then
53 if q
[j
][k
]='x' then begin inc(k
); t
:=getsum(q
[j
],k
); if t
=0 then t
:=1; p
[j
,1]:=t
; end
54 else if q
[j
][k
]='y' then begin inc(k
); t
:=getsum(q
[j
],k
); if t
=0 then t
:=1; p
[j
,2]:=t
; end;
58 function next(j
:longint):longint;
64 for i
:=j
+1 to lenc
do if c
[i
,0]=0 then inc(next
) else break
;
68 assign(input
,'multiply.dat'); reset(input
);
69 assign(output
,'multiply.out'); rewrite(output
);
71 if st
='0' then begin writeln
; writeln(0); close(input
); close(output
); halt
; end;
72 if (st
[1] in ['x'..'y']) or (st
[1] in ['0'..'9']) then st
:='+'+st
;
76 if st
='0' then begin writeln
; writeln(0); close(input
); close(output
); halt
; end;
77 if (st
[1] in ['x'..'y']) or (st
[1] in ['0'..'9']) then st
:='+'+st
;
83 c
[(i
-1)*lenb
+j
,0]:=a
[i
,0]*b
[j
,0];
84 c
[(i
-1)*lenb
+j
,1]:=a
[i
,1]+b
[j
,1];
85 c
[(i
-1)*lenb
+j
,2]:=a
[i
,2]+b
[j
,2];
88 for i
:=1 to lena
*lenb
do
90 if (i
<>j
) and (c
[i
,1]=c
[j
,1]) and (c
[i
,2]=c
[j
,2]) then
93 c
[j
,0]:=0; c
[j
,1]:=0; c
[j
,2]:=0;// dec(lenc);
98 if (c
[i
,1]<c
[j
,1]) or ((c
[i
,1]=c
[j
,1]) and (c
[i
,2]>c
[j
,2])) then
100 c
[0]:=c
[i
]; c
[i
]:=c
[j
]; c
[j
]:=c
[0];
102 if c
[1,0]<0 then write(' ');
107 if (abs(c
[i
,0])=1) and (c
[i
,1]=0) and (c
[i
,2]=0) then write(' ');
111 if c
[i
,1]<>1 then write(c
[i
,1]);
116 if c
[i
,2]<>1 then write(c
[i
,2]);
118 if c
[next(i
),0]<>0 then write(' ');
123 if c
[1,0]<0 then write('-');
124 // if abs(c[1,0])<>1 then write(abs(c[1,0]));
129 if (abs(c
[i
,0])<>1) or ((abs(c
[i
,0])=1) and (c
[i
,1]=0) and (c
[i
,2]=0)) then write(abs(c
[i
,0]));
130 if c
[i
,1]<>0 then write('x',len(c
[i
,1]));
131 if c
[i
,2]<>0 then write('y',len(c
[i
,2]));
133 if c
[next(i
),0]>0 then write('+ ') else
134 if c
[next(i
),0]<0 then write('- ');
136 close(input
); close(output
);