평균 구하기
문제 설명
자연수 N이 주어진다. N을 이진수로 바꿔서 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 자연수 N이 주어진다. (1 ≤ N ≤ 100,000,000,000,000)
출력
N을 이진수로 바꿔서 출력한다. 이진수는 0으로 시작하면 안 된다.
Python 코드
# 첫째 줄에 자연수 N을 입력하고 정수형으로 변환 N = int(input()) # N을 이진수로 변환하고 앞의 0b를 제외한 값을 저장 N = bin(N)[2:] # 이진수로 변환한 결과 출력 print(N) # print(bin(n)[2:]) # print(bin(int(input()))[2:])
* 참고 링크 : https://brightnightsky77.tistory.com/122
def trans(n): if (n<1): return '0' elif (n==1): return '1' if (n%2==0): return trans(int(n/2)) + '0' elif (n%2==1): return trans(int(n/2)) + '1' n = int(input()) answer = trans(n) print(answer)
* 참고 링크 : https://velog.io/@sxxzin/BaekjoonPython%EC%9D%B4%EC%A7%84%EC%88%98-%EB%B3%80%ED%99%98
https://my-coding-notes.tistory.com/137
C++ 코드
#include <iostream> using namespace std; int facto(int n) { if (n <= 1) return 1; else return n * facto(n - 1); } int main() { int n; cin >> n; cout << facto(n) << '\n'; }
* 참고 링크 : https://codesyun.tistory.com/73
출처
'코딩테스트 > 백준 알고리즘' 카테고리의 다른 글
[백준 알고리즘] 15829번 Hashing (0) | 2022.03.12 |
---|---|
[백준 알고리즘] 10162번 전자레인지_그리디알고리즘 (0) | 2022.03.12 |
[백준 알고리즘] 10872번 팩토리얼 파이썬 (0) | 2022.02.25 |
[백준 알고리즘] 15829번 Hashing (0) | 2022.02.18 |
[백준 알고리즘] 2606번 바이러스 (0) | 2022.02.14 |