-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1093_StringAPlusB.py
More file actions
46 lines (44 loc) · 891 Bytes
/
1093_StringAPlusB.py
File metadata and controls
46 lines (44 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def big(s):
while(len(s) < 4):
s += '0'
s = sorted(s, reverse=True)
number = ''
for i in range(len(s)):
number += s[i]
return eval(number)
def small(s):
s = sorted(s)
number = ''
for i in range(len(s)):
if s[i] == '0':
continue
number += s[i]
if number == '':
return 0
return eval(number)
s = input()
a = big(s)
b = small(s)
while a != b:
print(a, end=' - ')
s = str(a)
s = sorted(s)
for i in range(len(s)):
print(s[i], end='')
print(' = ', end='')
c = a - b
s = str(c)
for i in range(4 - len(s)):
print('0', end='')
a = big(str(c))
b = small(str(c))
print(s)
if c == 6174:
break
if a == b:
out = ''
s = str(a)
for i in range(4 - len(s)):
out += '0'
out += s
print(out, '-', out, '= 0000', end='')