-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1123.py
73 lines (58 loc) · 2.03 KB
/
1123.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
# 1123. Зарплата
# solved
"""
If right half (reversed) less than left half, we reverse left half and replace the right one with it
If right half (reversed) is more than left half, we increase left half by 1 and replace it the right one with it
"""
import math
input_salary = input()
input_half_len = math.ceil(len(input_salary)/2)
equal_halves = 0
center_num = ''
result = ''
# for salary between 0 and 99
if len(input_salary) == 1:
result = input_salary
elif len(input_salary) == 2:
if int(input_salary[0]) < int(input_salary[1]):
result = str(int(input_salary[0]) + 1) + str(int(input_salary[0]) + 1)
elif int(input_salary[0]) > int(input_salary[1]):
result = input_salary[0] + input_salary[0]
else:
result = input_salary
# for the rest
else:
if len(input_salary) % 2 == 0:
even_digits = 1
left_half = input_salary[:input_half_len]
right_half = input_salary[input_half_len:]
else:
even_digits = 0
left_half = input_salary[:input_half_len - 1]
center_num = input_salary[input_half_len - 1:input_half_len]
right_half = input_salary[input_half_len:]
for i in range(len(left_half)):
if right_half[i] < left_half[-i - 1]:
right_half = left_half[::-1]
if even_digits == 1:
result = left_half + right_half
else:
result = left_half + center_num + right_half
equal_halves = 0
break
elif right_half[i] > left_half[-i - 1]:
if even_digits == 1:
left_half = str(int(left_half) + 1)
right_half = left_half[::-1]
result = left_half + right_half
else:
left_half = str(int(left_half)*10 + int(center_num) + 1)
right_half = (left_half[::-1])[1:]
result = left_half + right_half
equal_halves = 0
break
else:
equal_halves = 1
if equal_halves == 1:
result = input_salary
print(result)