본문 바로가기

알고리즘/백준-파이썬

[백준] 11005번 (python 파이썬)

https://www.acmicpc.net/problem/11005

 

11005번: 진법 변환 2

10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를

www.acmicpc.net

 

number, base = map(int, input().split())

t = number
result = []
while t != 0:
  t, r = divmod(t, base)
  if r >= 10:
    r = ord("A") + (r-10)
    result.append(chr(r))
  else:
    result.append(str(r))
print("".join(reversed(result)))