PS/BOJ
[백준]진법 변환 2
RUBY_루비
2024. 2. 18. 23:00
출처:: https://www.acmicpc.net/problem/11005
분류::Brute Force
1. 문제 이해 및 해결과정
O(logb N) |
2. 풀이방법
n, b = map(int, input().split())
sol =""
while n > 0:
re = n%b
if (re < 10) :
sol += str(re)
else:
sol += chr(re - 10 + ord('A'))
n= n//b
print(sol[::-1])
3. 오답원인
- sol 에 이진법 수 계산 과정 더할 시, re는 숫자 sol문자열 이므로 str(re)를 하지 않을 경우 run time type error 발생한다.
4. 알게된 점
-python 문자열 reverse 출력 : str[::-1]