# STEP 1 recieve the input and split it by blank
N, B = input().split()
# STEP 2 string to list then reverse
N = list(N.strip())
N = N[::-1]
# STEP 3
B = int(B)
answer = 0
# STEP 4 if the value is numeric, multiply by B to the i-th power
# else, convert the character into an assigned value then multiply by B^i
for i,x in enumerate(N):
if x.isnumeric():
answer += int(x) * (B ** i)
else:
answer += (ord(x)-55) * (B ** i)
print(answer)
N, B = input().split()
print(int(N, int(B)))
int( 'string', int )
int()를 이렇게 쓸 수 있는지 첨알았다..!
string을 B 진법으로 바꿔 줌.
int('11', 2) # 3
int('AA', 11) # 120
### 풀다보니..
- N이 B진수는 가질 수 없는 수를 가진 경우는 아예 제외 된 경우 인가봄
- 문자처리를 상당히 쉽게 내준 문제 인듯