https://programmers.co.kr/learn/courses/30/lessons/12911
#include <string>
#include <vector>
using namespace std;
int cal(vector<int> bin){
int res =0 ;
int mul = 1;
for(int i=0;i<bin.size();i++){
res += bin[i]*mul;
mul *= 2;
}
return res;
}
int solution(int n) {
vector<int> binaryN;
while(n != 0){
binaryN.push_back(n % 2);
n /= 2;
}
binaryN.push_back(0);
int one=0;
for(int i=0;i<binaryN.size();i++){
if(binaryN[i] == 1){
if(binaryN[i+1] == 0){
binaryN[i] = 0;
binaryN[i+1] = 1;
for(int j=0;j<one;j++){
binaryN[j] = 1;
}
return cal(binaryN);
}else{
one++;
binaryN[i] = 0;
}
}
}
}
#include<iostream>
using namespace std;
int nextBigNumber(int n)
{
int answer = 0;
int ac = 0, k = n;
while (k != 0) {
ac += k % 2;
k /= 2;
}
for (int i = n + 1;; i++) {
int count = 0;
k = i;
while (k != 0) {
count += k % 2;
k /= 2;
}
if (count == ac) {
answer = i;
break;
}
}
return answer;
}
int main()
{
int n = 78;
//아래는 테스트 출력을 위한 코드입니다.
cout << nextBigNumber(n);
}