chcialem odejmowanie koniecznie na duzych stringach zrobic. No i zrobilem (ale nie zawsze mi dziala poprawnie). Chciałbym żeby ktos rzucil okiem na kod i wytknal jakies bledy, podpowiedzial jakies poprawki (tak zeby zawsze dzialalo). W koncu na błędach człowiek sie uczy, a zapytać kogo nie mam, bo w mojej wsi to sie nikt nie zna.
function toDigit(x : Char) : Byte;
begin
toDigit:=Ord(x) - 48;
end;
function toChar(x : Byte) : Char;
begin
toChar:=Chr(x + 48);
end;
function Compare(a, b : String) : Integer;
{
-1 : a < b
0 : a = b
1 : a > b
}
var
temp : Integer;
begin
if length(a) < length(b) then temp:=-1;
if length(b) > length(b) then temp:=1;
if length(a) = length(b) then
begin
if a > b then temp:=1;
if a < b then temp:=-1;
if a = b then temp:=0;
end;
Compare:=temp;
end;
function substraction(a, b : String) : String;
var
i, j, temp : Byte;
S : String;
flag : Boolean;
begin
flag:=TRUE;
if Compare(a, b) = -1 then
begin
Replace(a, b);
flag:=FALSE;
end;
while length(a) > length(b) do
b:='0' + b;
while length(b) > length(a) do
a:='0' + a;
for i:=length(a) downto 1 do
begin
if toDigit(b[i]) > toDigit(a[i]) then
begin
if toDigit(a[i - 1]) > 0 then
begin
temp:=toDigit(a[i]) + 10 - toDigit(b[i]);
a[i - 1]:=toChar(toDigit(a[i - 1]) - 1);
end else if toDigit(a[i - 1]) = 0 then
begin
j:=i;
while toDigit(a[j]) = 0 do
begin
a[j]:=toChar(9);
dec(j);
end;
a[j]:=toChar(toDigit(a[j]) - 1);
temp:=10 - toDigit(b[i]);
end
end else if toDigit(b[i]) <= toDigit(a[i]) then
temp:=toDigit(a[i]) - toDigit(b[i]);
S:=toChar(temp) + S;
end;
if flag = FALSE then
S:='-' + S;
substraction:=S;
end;