[COS Pro python 1급] p진법 to q진법
2023. 3. 14. 18:04ㆍ자격증/COS Pro 1급 Python
D-4
def toten(n,p):
ten=0
for i in range(len(n)):
ten+=int(n[-(i+1)])*(p**i)
return ten
def toq(n,q):
qnum=''
while n>0:
mok,namuji=divmod(n,q)
qnum+=str(namuji)
n=mok
return qnum[::-1]
def solution(s1, s2, p, q):
answer = ''
ten1=toten(s1,p)
ten2=toten(s2,p)
sum=ten1+ten2
answer=toq(sum,q)
return answer
문자열 str뒤집기; str[::-1]
divmod(a, b)함수; a를 b로 나눈 몫과 나머지를 튜플형식으로 반환,
'자격증 > COS Pro 1급 Python' 카테고리의 다른 글
[COS Pro python 1급] (0) | 2023.03.18 |
---|---|
[COS Pro python 1급] 몇번 연산을 해야하나요 (0) | 2023.03.16 |
[COS Pro python 1급] 병합 and 정렬 (0) | 2023.03.13 |
[COS Pro python 1급] 체스의 나이트 (0) | 2023.03.12 |
[COS Pro python 1급] 2차원 리스트 방향좌표로 접근하기 (0) | 2023.03.12 |