-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
35 lines (31 loc) · 802 Bytes
/
test.py
File metadata and controls
35 lines (31 loc) · 802 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
import sys
oBase = 10
nBase = 16
def convbase(oBase,nBase,num):
n = 0
for digit in num:
n *= oBase
if '0' <= digit <= '9':
n += ord(digit) - ord('0')
else:
n += int(ord(digit.lower()) - ord('a') + 10)
if n == 0:
print("0")
else:
result = ""
while n != 0:
if n%nBase > 9:
result = chr(ord('a') + (n%nBase-10) % nBase) + result
else:
result = chr(ord('0') + n % nBase) + result
n //= nBase
print(result)
for line in sys.stdin:
n = 0
line = line.strip()
if line.find('>')!=-1:
oBase, nBase = line.split('>')
continue
else:
num = line.strip()
convbase(int(oBase),int(nBase),num)