# Untitled

unknown
plain_text
3 years ago
2.2 kB
7
Indexable
Never
```uses crt;//xu ly so lon

//ham tinh tong 2 so lon
function sum(a,b:string):string;
var
tong,nho,x,y,i:longint;
c:string;
begin
nho:=0;
c:='';
while (length(a)<length(b)) do a:='0'+a;
while (length(b)<length(a)) do b:='0'+b; // a va b co do dai bang nhau
for i:=length(a) downto 1 do
begin
x:=ord(a[i]) - ord('0');//so a[i]
y:=ord(b[i]) - ord('0');//so b[i]
tong:= x+y+nho;
nho:=tong div 10;
c:=chr(tong mod 10 +48)+c;
end;
if(nho>0) then c:='1'+c;
sum:=c;
end;

//ham tinh hieu 2 so lon
function sub(a,b:string):string;
var
c:string;
i,hieu,nho:longint;
begin
nho:=0;
c:='';
while(length(a)<length(b)) do a:='0'+a;
while(length(b)<length(a)) do b:='0'+b; // a va b co do dai bang nhau
for i:=length(a) downto 1 do
begin
hieu:=ord(a[i]) - ord(b[i]) -nho;
if (hieu<0) then
begin
hieu:=hieu+10;
nho:=1;
end
else    nho:=0;
c:=chr(hieu+48)+c;
end;
while(length(c)>1) and (c[1]='0') do delete(c,1,1);
sub:=c;
end;

function nhan(a:string;b:longint):string;
var
i,nho,s:longint;
c,tam:string;
begin
c:='';
nho:=0;
for i:=length(a) downto 1 do
begin
s:=(ord(a[i])-ord('0'))*b+nho;
nho:= s div 10;
c:=chr(s mod 10 +48)+c;
end;
if(nho>0) then str(nho,tam) else tam:='';
nhan:=tam+c;
end;
function nhansolon(a,b:string):string;
var
sum1,tam:string;
m,i,j:longint;
begin
sum1:='';
m:=-1;
for i:=length(a) downto 1 do
begin
inc(m);
tam:=nhan(b,ord(a[i])-48);
for j:=1 to m do tam:=tam+'0';
sum1:=sum(tam,sum1);

end;
nhansolon:=sum1;
end;

var
f:text;
s1,s2,s3,s4,s5:string;
begin
clrscr;
assign(f,'bai1.inp');reset(f);
readln(f,s1);
readln(f,s2);
close(f);

assign(f,'bai1.out');rewrite(f);
//s3:=sum(s1,s2);
//s4:=sub(s1,s2);
s5:=nhansolon(s1,s2);
write(f,s5);close(f);
//writeln(low(word));
//writeln(high(word));

readln;
end.```