Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- knn
- PAPER
- Scienceplots
- n_sample
- MAPE
- mMAPE
- RMES
- SMAPE
- Tire
- Overleaf
- 스택
- Mae
- n_neighbors
- Python
- 논문작성
- TypeError
- 프로그래머스
- 에러해결
- iNT
- mes
- Pycaret
- 카카오
- python 갯수세기
- 평가지표
- 논문editor
- 파이썬을파이썬답게
- Alignments
- KAKAO
- 코테
- 논문
Archives
- Today
- Total
EunGyeongKim
[월간코드]3진법 뒤집기 본문
더 많은 코드 (https://github.com/EunGyeongKim/TIL)
1. 문제 설명
자연수 n이 매개변수로 주어집니다. n을 3진법 상에서 앞뒤로 뒤집은 후, 이를 다시 10진법으로 표현한 수를 return 하도록 solution 함수를 완성해주세요.
2. 제한사항
• n은 1 이상 100,000,000 이하인 자연수입니다.
3. 입출력 예
n | result |
---|---|
45 | 7 |
125 | 229 |
4. 코드
import string
#진법 변환
tmp = string.digits+string.ascii_lowercase
def convert(num, base) :
q, r = divmod(num, base)
if q == 0 :
return tmp[r]
else :
return convert(q, base) + tmp[r]
def solution(n):
answer = int(convert(n, 3)[::-1], 3)
return answer
'코딩테스트 > programmers' 카테고리의 다른 글
[2019 kakao]실패율 (0) | 2022.09.20 |
---|---|
[2021 kakao] 숫자 문자열과 영단어 (0) | 2022.09.20 |
[2021 kakao]신규아이디 추천 (0) | 2022.09.20 |
[2022 kakao]성격유형 검사하기 (1) | 2022.09.20 |
[월간코드] n^2 배열 자르기 (0) | 2022.09.20 |
Comments