Notice
														
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
													Link
													
											
									할껀하고놀자
[백준] 11179번 2진수 뒤집기 (C++, python3) 본문
728x90
    
    
  C++ code
#include<iostream>
#include<string>
#include<vector>
#include<deque>
#include<math.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	long s;
	cin >> s;
	deque<int> list;
	while (s != 1) {
		list.push_front(s % 2);
		s /= 2;
	}
	list.push_front(1);
	deque<int> new_list = list;
	for (int i = 0; i <list.size(); i++) {
		new_list[i] = list[list.size() - 1 - i];
	}
	int sum = 0;
	int idx = 0;
	while (!new_list.empty())
	{
		int num = new_list[new_list.size()-1];
		new_list.pop_back();
		sum += num * pow(2, idx);
		idx++;
	}
	cout << sum << "\n";
	return 0;
}
python code
n = bin(int(input()))[2:]   # 2 진수로 만들어 주는 bin
print(int(n[::-1],2))       # 이걸 다시 10진수로 만들어 줄 때
'[IT] > 백준' 카테고리의 다른 글
| [백준] 13420 사칙연산 (0) | 2019.09.29 | 
|---|---|
| [백준] 1010번 다리놓기 (0) | 2019.09.28 | 
| [백준] 2744번 대소문자 바꾸기 (0) | 2019.09.21 | 
| [백준] 1789번 수들의 합 (0) | 2019.09.21 | 
| [백준] 11653번 소인수분해 - (파이썬,C++ 속도차 실화냐..) (0) | 2019.09.21 | 
			  Comments
			
		
	
               
           
					
					
					
					
					
					
				 
             
								