평균 구하기

 

 문제 설명

 

자연수 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

 출처

 

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

+ Recent posts