Advertisement
SoloBoss

A*B

Jan 18th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. function plus(s, s1: string): string;
  9. var
  10. s2: string;
  11. i, x, y, c, bon: integer;
  12.  
  13. begin
  14.  
  15. if length(s) < length(s1) then
  16. begin
  17. s2 := s;
  18. s := s1;
  19. s1 := s2
  20. end;
  21. bon := 0;
  22. for i := length(s) downto (length(s) - length(s1) + 1) do
  23. begin
  24. x := strtoint(s[i]);
  25. y := strtoint(s1[length(s1) -(length(s) - i)]);
  26.  
  27. c := x + y + bon;
  28.  
  29. bon := c div 10;
  30. c := c mod 10;
  31. s2 := inttostr(c);
  32. s[i] := s2[1];
  33. end;
  34.  
  35. i := (length(s) - length(s1));
  36.  
  37. while (i >= 1) and (bon > 0) do
  38. begin
  39. x := strtoint(s[i]);
  40. c := x + bon;
  41. bon := c div 10;
  42. c := c mod 10;
  43. s2 := inttostr(c);
  44. s[i] := s2[1];
  45. dec(i);
  46. end;
  47.  
  48. if (bon > 0) then
  49. begin
  50. s2 := inttostr(bon);
  51. s := s2 + s;
  52. end;
  53.  
  54. plus := s;
  55. end;
  56.  
  57. var
  58. s, s1, s2, sist, sum: string;
  59. i, j, x, ost, ch, k, time: integer;
  60.  
  61. begin
  62. readln(s);
  63. readln(s1);
  64.  
  65. if (s = '0') or (s1 = '0') then
  66. begin
  67. writeln('0');
  68. halt;
  69. end;
  70.  
  71. sum := '0';
  72. if length(s) < length(s1) then
  73. begin
  74. s2 := s1;
  75. s1 := s;
  76. s := s2;
  77. end;
  78.  
  79. sist := s;
  80. time := 0;
  81. for j := length(s1) downto 1 do
  82. begin
  83. s := sist;
  84.  
  85. ch := strtoint(s1[j]);
  86.  
  87. ost := 0;
  88.  
  89. for i := length(s) downto 1 do
  90. begin
  91. x := strtoint(s[i]) * ch + ost;
  92.  
  93. ost := x div 10;
  94.  
  95. s2 := inttostr(x mod 10);
  96.  
  97. s[i] := s2[1];
  98.  
  99. end;
  100.  
  101. if ost > 0 then
  102. s := inttostr(ost) + s;
  103.  
  104. for k := 1 to time do
  105. s := s + '0';
  106.  
  107. sum := plus(sum , s);
  108.  
  109. inc(time);
  110. end;
  111.  
  112. writeln(sum);
  113.  
  114. readln;readln;
  115.  
  116. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement