-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice49.py
54 lines (42 loc) · 1.05 KB
/
practice49.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
#small hexxeh
hexDict = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15}
hexArr = '0123456789abcdef'
def hexStrToDecimal(hexStr):
decimal = 0
power = 1
s = hexStr[::-1]
for c in s:
decimal += hexDict[c] * power
power *= 16
return decimal
def decimalToHexStr(decimal):
hexVal = ""
while decimal:
rem = decimal % 16
hexVal += hexArr[rem]
decimal /= 16
if hexVal:
return hexVal[::-1]
return "0"
def increaseHex(hexStr):
decVal = hexStrToDecimal(hexStr)
decVal += 1
return decimalToHexStr(decVal)
def isSameReversed(s):
for i in range(len(s)/2):
if s[i] != s[len(s)-1-i]:
return False
return True
k = "d3e01e"
k = increaseHex(k)
while not isSameReversed(k):
k = increaseHex(k)
print k
exit(0)
t = int(raw_input())
for _ in range(t):
k = raw_input().strip()
k = increaseHex(k)
while not isSameReversed(k):
k = increaseHex(k)
print k