anon20016

B Деление уголком!

Nov 14th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import math
  2.  
  3. a = input()
  4. b = input()
  5. A = int(a)
  6. B = int(b)
  7.  
  8. c = 0
  9. ind = 0
  10. d = 0
  11. dd = 0
  12.  
  13. ans = A // B
  14.  
  15. if ans == 0:
  16. print(a + " |" + b)
  17. print((len(a) + 1) * " " + "+" + "-" * len(b))
  18. print((len(a) + 1) * " " + "|0")
  19. exit(0)
  20.  
  21. print(a + " |" + b)
  22.  
  23. lg = 0
  24.  
  25. line = 0
  26.  
  27. while ind < len(a):
  28. while c < B and ind < len(a):
  29. c = c * 10 + int(a[ind])
  30. ind += 1
  31. m = (c // B) * B
  32. offset = len(str(c)) - len(str(m))
  33.  
  34. if c - m == 0:
  35. dd += len(str(c)) + 1
  36. else:
  37. dd += len(str(c)) - len(str(c - m))
  38. c -= m
  39. while c < B and ind < len(a):
  40. c = c * 10 + int(a[ind])
  41. ind += 1
  42.  
  43. string1 = (lg + offset) * " " + str(m)
  44. string2 = lg * " " + (ind - lg) * "-"
  45. string3 = (ind - len(str(c))) * " " + str(c)
  46.  
  47. if line == 0:
  48. print(string1 + " " * (1 + len(a) - len(string1)) + "+" + "-" * max(len(b), len(str(ans))))
  49. print(string2 + " " * (1 + len(a) - len(string2)) + "|" + str(ans))
  50. print(string3)
  51. else:
  52. print(string1)
  53. print(string2)
  54. print(string3)
  55.  
  56. line += 1
  57. lg = ind - len(str(c))
  58.  
  59. if c >= B:
  60. m = (c // B) * B
  61. offset = len(str(c)) - len(str(m))
  62. print((lg + offset) * " " + str(m))
  63. c -= m
  64. print(lg * " " + (ind - lg) * "-")
  65. print((ind - len(str(c))) * " " + str(c))
Add Comment
Please, Sign In to add comment