Вы находитесь на странице: 1из 3

const fi='';

fo='';
var f:text;
i,n,nho,muon,s,j,t:longint;
so_am:boolean;
a,b,c:array[0..5000] of integer;
ch:char;
begin
assign(f,fi);
reset(f);
while not EOLN(f) do
begin
read(f,ch);
if (ch>='0') and (ch<='9') then
begin
n:=n+1;
a[n]:=ord(ch) -48;
end;
end;
for i:=1 to n div 2 do
begin
t:=a[i];
a[i]:=a[n-i+1];
a[n-i+1]:=t;
end;
while (n>1) and (a[n]=0) do n:=n-1;
a[0]:=n;
n:=0;
readln(f);
while not EOln(f) do
begin
read(f,ch);
if (ch>='0') and (ch<='9') then
begin
n:=n+1;
b[n]:=ord(ch) -48;
end;
end;
for i:=1 to n div 2 do
begin
t:=b[i];
b[i]:=b[n-i+1];
b[n-i+1]:=t;
end;
while (n>1) and (b[n]=0) do n:=n-1;
b[0]:=n;
close(f);
so_am:=false;
while (a[0]>1) and (a[a[0]]=0) do a[0]:=a[0]-1;
while (b[0]>1) and (b[b[0]]=0) do b[0]:=b[0]-1;

if a[0]<b[0] then so_am:=true


else
if a[0]=b[0] then
begin
i:=a[0];
while (a[i]=b[i]) and (i>1) do i:=i-1;
if a[i]<b[i] then so_am:=true;
end;
if so_am=true then
begin
c:=a;
a:=b;
b:=c;
end;
{---------------------------------------------------------------------}
assign(f,fo);
rewrite(f);
fillchar(c,sizeof(c),0);
c[0]:=a[0];
nho:=0;
for i:=1 to c[0] do
begin
s:=a[i]+b[i]+nho;
c[i]:=s mod 10;
nho:=s div 10;
end;
if nho>0 then
begin
c[0]:=c[0]+1;
c[c[0]]:=nho;
end;
for i:=c[0] downto 1 do write(f,c[i]);
writeln(f);
{---------------------------------------------------------------------}
fillchar(c,sizeof(c),0);
c[0]:=a[0];
muon:=0;
for i:=1 to c[0] do
begin
s:=a[i]-b[i]-muon;
if s>=0 then
begin
c[i]:=s;
muon:=0;
end
else
begin
c[i]:=10+s;
muon:=1;
end;

end;
while (c[0]>1) and(c[c[0]]=0) do c[0]:=c[0]-1;
if so_am=true then write(f,'-');
for i:=c[0] downto 1 do write(f,c[i]);
writeln(f);
{---------------------------------------------------------------------}
fillchar(c,sizeof(c),0);
for i:=1 to a[0] do
begin
nho:=0;
for j:=1 to b[0] do
begin
s:=a[i]*b[j]+nho+c[i+j-1];
c[i+j-1]:=s mod 10;
nho:=s div 10;
end;
j:=i+b[0];
while nho>0 do
begin
nho:=nho+c[j];
c[j]:=nho mod 10;
nho:=nho div 10;
end;
end;
c[0]:=a[0]+b[0];
while (c[c[0]]=0) and (c[0]>1) do c[0]:=c[0]-1;
for i:=c[0] downto 1 do write(f,c[i]);
close(f);
end.

Вам также может понравиться