-
Notifications
You must be signed in to change notification settings - Fork 0
/
1608.py
72 lines (60 loc) · 1.89 KB
/
1608.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 1608. Счастливые билеты 2008
# 100-999 unlucky tickets
"""
counter = 0
for i in range(100, 1000):
num = str(i)
same_num = 0
for j in range(len(num) // 2):
if num[j] == num[len(num) - j-1]:
same_num = 1
if same_num == 1:
counter += 1
print(str(counter))
"""
"""
#1-9 and 10-99
unlucky_dict = {1:0, 2:9}
unlucky_amount = 0
for i in range(3, 19):
if i%2 == 1:
unlucky_amount = unlucky_dict.get(i-1) * 10
else:
unlucky_amount = 90 * (unlucky_dict.get(i-2) + 10**(i-3))
unlucky_dict[i] = unlucky_amount
print(unlucky_dict)
input_data = input().split(' ')
a = input_data[0]
b = input_data[1]
unlucky_in_a = 0
unlucky_in_b = 0
for i in range(len(b)):
#print('i=' + str(i) + ' ' + 'b[i]=' + b[i] + ' ' + 'len(b)-i=' + str(len(b)-i))
# exclude max i
# range between 1 and 10**(len(b))-1, if 1234, then its 1-999
if i < len(b) - 1:
unlucky_in_b = unlucky_in_b + unlucky_dict.get(len(b)-i - 1)
# range between 10**(len(b)) and b, if 1234, then its 1000-1234
if i < len(b) - 1:
unlucky_in_b = unlucky_in_b + unlucky_dict.get(len(b) - i - 1)
print(unlucky_in_b)
result = (b-a) - (unlucky_in_b - unlucky_in_a)
"""
# works for 1-9 - 10000-99999, doesn't work for 100000-999999
num = str(input())
counter = 0
for i in range(len(num) // 2):
if i == 0:
# first and last
counter = 9 * 10**(len(num) - 2)
#for j in range(len(num)//6):
#if len(b) > 5:
# print(str(9 * 9 * 10**(len(num) - 4)))
# counter = counter - 9 * 9 * 10**(len(num) - 4)
else:
# all other digits
counter = counter + 10*9 * 10**(len(num) - 3)
#for j in range (len(num)//2 - (len(num)//2 - 1)):
# print(str(9 * 10**(len(num) - 3)))
# counter = counter - 9 * 10**(len(num) - 3)
print(str(10**(len(num) - 1)) + '-' + num + ' = ' + str(counter))