티스토리 뷰
#include <string>
#include <vector>
using namespace std;
int solution(int n) {
int answer = 0;
int n_one_cnt = 0, temp = n;
while(temp > 0){
if(temp%2 == 1) n_one_cnt += 1;
temp = temp/2;
}
int temp_one_cnt;
int num = n;
while(true){
temp_one_cnt = 0;
num += 1;
temp = num;
while(temp > 0){
if(temp%2 == 1) temp_one_cnt += 1;
temp = temp/2;
}
if(temp_one_cnt == n_one_cnt){
return num;
}
}
return answer;
}
'알고리즘 > C++' 카테고리의 다른 글
[C++] 프로그래머스 폰켓몬 (0) | 2020.03.08 |
---|---|
[C++] 프로그래머스 땅따먹기 (0) | 2020.03.08 |
[C++] 프로그래머스 올바른 괄호 (0) | 2020.03.08 |
[C++] 프로그래머스 가장 큰 정사각형 (0) | 2020.03.08 |
[C++] 프로그래머스 카펫 (0) | 2020.03.08 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 실시간 데이터베이스
- Django
- 장고 게시판
- cleaned_data
- 데이터베이스 추천
- 웹 배포
- django clean
- django 로그인접근
- UITableViewController Not Working
- CellForRowAt 호출안됨
- django 게시판
- django 개발일지
- 알파벳 카운팅
- pythonanywhere배포방법
- iOS 데이터베이스
- 장고 태그달기
- Firebase 데이터베이스 추천
- Realtime Database
- CellForRowAt Not Called
- iOS 검은 화면
- python 웹 배포
- iOS UITableView 출력안됨
- django 태그
- 까만 화면
- iOS 화면 안나옴
- pythonanywhere배포
- ModelForm Form 차이
- django tag
- django pythoneverywhere
- 테이블출력안됨
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함