SlepoiKrot

Untitled

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