-
Notifications
You must be signed in to change notification settings - Fork 0
/
aliennumbers.py
31 lines (23 loc) · 976 Bytes
/
aliennumbers.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
num_cases = int(input())
for case in range(num_cases):
alien_number, source_language, target_language = input().split()
source_map = {}
target_map = {}
for i in range(len(source_language)):
source_map[source_language[i]] = i
for i in range(len(target_language)):
target_map[i] = target_language[i]
alien_number_arabic = []
for c in alien_number:
alien_number_arabic.append(str(source_map[c]))
decimal_value = 0
for i in range(0, len(alien_number_arabic)):
decimal_value += int(alien_number_arabic[len(alien_number_arabic) - 1 - i]) * (len(source_language)**i)
target_number_arabic = []
while decimal_value != 0:
target_number_arabic.append(decimal_value % (len(target_language)))
decimal_value = int(decimal_value / len(target_language))
target_number = ''
for i in range(len(target_number_arabic)):
target_number += target_map[target_number_arabic[len(target_number_arabic) - 1 - i]]
print('Case #' + str(case + 1) + ': ' + target_number)