Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- a, b = int(input()), int(input())
- if a >= b and a > 9:
- c = a // b
- r = []
- m = list(str(a))
- pos = [0]
- length = len(m)
- ostatok = a
- z = 0
- while ostatok >= b:
- k = m[0]
- i = 1
- z = 0
- while int(k) < b and i != len(m):
- if int(k) == 0:
- z += 1
- k += m[i]
- i += 1
- m = [s for s in str(int(k) % b) if int(k) % b != 0] + m[i:]
- while len(m) != 0 and m[0] == '0':
- m = m[1:]
- pos.append(length - len(m))
- r.append(int(k))
- r.append(b * (int(k) // b))
- if len(m) != 0:
- ostatok = int(''.join(m))
- else:
- ostatok = 0
- pos[-1] = length - len(str(ostatok))
- if len(pos) > 1:
- pos[-2] += z
- r.append(ostatok)
- a = str(a)
- b = str(b)
- c = str(c)
- r = list(map(str, r))
- print(a + ' |' + b)
- true = [(pos[0], r[0], r[1])]
- j = 2
- for i in range(1, len(pos) - 1):
- true.append((pos[i], r[j], r[j + 1]))
- j += 2
- true.append((pos[-1], r[-1]))
- s = ' ' * (len(true[0][1]) - len(true[0][2])) + true[0][2]
- print(s + ' ' * (len(a) - len(s)) + ' +' + '-' * max(len(c), len(b)))
- s = true[1][0] + len(true[1][1])
- print('-' * s + ' ' * (len(a) - s) + ' |' + str(c))
- for i in range(1, len(true) - 1):
- p1 = true[i][0]
- p2 = true[i][0] + len(true[i][1]) - len(true[i][2])
- p3 = true[i + 1][0] - true[i][0] + len(true[i + 1][1])
- print(' ' * p1 + true[i][1])
- print(' ' * p2 + true[i][2])
- print(' ' * p1 + '-' * p3)
- print(' ' * true[-1][0] + true[-1][1])
- else:
- if a < b:
- a, b = str(a), str(b)
- print(a + ' |' + b)
- print(' ' * len(a) + ' +' + '-' * len(b))
- print(' ' * len(a) + ' |' + '0')
- else:
- print(str(a) + ' |' + str(b))
- print(str(a // b * b) + ' +' + len(str(b)) * '-')
- print('- |' + str(a // b))
- print(str(a % b))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement