SlepoiKrot

Untitled

Feb 21st, 2018
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program NUMBER1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils,
  7.   Math;
  8.  
  9. var
  10.   s1, s2, s, sw: string;
  11.   i, asize, bsize, per, j : integer;
  12.   a, b, sum: array [1..10001] of integer;
  13.   x, y, c, plus: boolean;
  14. begin
  15.   readln (s);
  16.   i := 1;
  17.   x := true;
  18.   y := true;
  19.   while (ord(s[i]) - 48 < 0) or (ord(s[i]) - 48 > 9) do begin
  20.     if (s[i] = '-') then
  21.       x := false;
  22.     inc(i);
  23.   end;
  24.   while (ord(s[i]) - 48 >= 0) and (ord(s[i]) - 48 <= 9) do begin
  25.     s1 := s1 + s[i];
  26.     inc (i);
  27.   end;
  28.   while i <= length(s) do begin
  29.    if (ord(s[i]) - 48 >= 0) and (ord(s[i]) - 48 <= 9) then
  30.     s2 := s2 + s[i];
  31.    if (s[i] = '-') then
  32.     y := false;
  33.    inc (i);
  34.   end;
  35.  
  36.   c := true;
  37.   if (length(s1) = length(s2)) then begin
  38.     for i := 1 to length (s1) do begin
  39.       if (s1[i] > s2[i]) then begin
  40.         c := true;
  41.         break;
  42.       end
  43.       else if (s1[i] < s2[i]) then begin
  44.         c := false;
  45.         break;
  46.       end;
  47.     end;
  48.   end
  49.   else if (length(s1) < length(s2))then
  50.     c := false;
  51.   if (c = false) then begin
  52.     sw := s1;
  53.     s1 := s2;
  54.     s2 := sw;
  55.   end;
  56.  
  57.   plus := true;
  58.   if ((x = false) and (y = true) and (c = true) or (x = true) and (y = false) and (c = false) or (x = false) and (y = false))  then
  59.     plus := false;
  60.  
  61.   asize := 10001;
  62.   bsize := 10001;
  63.   for i := length (s1) downto 1 do begin
  64.     dec (asize);
  65.     a[asize] := ord(s1[i]) - 48;
  66.   end;
  67.   for i := length (s2) downto 1 do begin
  68.     dec (bsize);
  69.     b[bsize] := ord(s2[i]) - 48;
  70.   end;
  71.  
  72.   if (y = true) and (x = true) or (x = false) and (y = false) then begin
  73.     per := 0;
  74.     for i := 10000 downto 1 do begin
  75.       per := per + a[i] + b[i];
  76.       sum [i] := per mod 10;
  77.       per := per div 10;
  78.     end;
  79.   end
  80.   else begin
  81.     per := 0;
  82.     for i := 10000 downto 1 do begin
  83.       per := per + a[i] - b[i] + 10;
  84.       sum[i] := per mod 10;
  85.       if (per < 10) then
  86.         per := -1
  87.       else
  88.         per := 0;
  89.     end;
  90.   end;
  91.   for i := 1 to 10000 do begin
  92.     if (sum[i] = 0) then
  93.       inc (j)
  94.     else
  95.       break;
  96.   end;
  97.   if (j >= 10000) then begin
  98.     writeln (0);
  99.     exit;
  100.   end;
  101.  
  102.   if (plus = false) then
  103.     write('-');
  104.   j := 1;
  105.   while (sum[j] = 0) do begin
  106.     inc (j);
  107.   end;
  108.   for i := j to 10000 do begin
  109.     write(sum[i]);
  110.   end;
  111.  
  112.  
  113.   readln;
  114.   readln;
  115. end.
RAW Paste Data