#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdint>
#include <limits>
int CountBit(std::int64_t N){
int C = 0;
for (std::size_t i = 0; i < std::numeric_limits<std::int64_t>::digits; i++){
if ((N&((1ull << i)))>0) C++;
}
return C;
}
std::string ltostr(std::int64_t N){
std::string str;
bool F = false;
std::string C = "01";
for (size_t i = std::numeric_limits<std::int64_t>::digits+1;i>0; i--){
if ((N&(1ull << (i-1))) == 0 && F == false) continue;
F = true;
str += C[(N&(1ull << (i - 1))) > 0];
}
return str;
}
std::string MakeHoge(std::string Bit){
char* P = NULL;
std::int64_t N =std::strtol(Bit.c_str(), &P, 2);//C99
if (*P != '\0') return "Error";
std::string R;
for (std::int64_t i = N+1; i < std::numeric_limits<std::int64_t>::max(); i++)
{
//R = ltostr(N);//selfmade
if (CountBit(i) == 3){
R = ltostr(i);//selfmade
break;
}
}
return R;
}
bool Show(std::string P, std::string S){
std::cout << P << " -> " << S << std::endl;
return true;
}
int main(){
std::int64_t MagicWord = 0;
std::string P;
std::string S;
P = "111";
S = MakeHoge(P);
Show(P, S);
P = "1110";
S = MakeHoge(P);
Show(P, S);
P = "110100";
S = MakeHoge(P);
Show(P, S);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGNzdGRpbnQ+CiNpbmNsdWRlIDxsaW1pdHM+CgppbnQgQ291bnRCaXQoc3RkOjppbnQ2NF90IE4pewoJaW50IEMgPSAwOwoKIAlmb3IgKHN0ZDo6c2l6ZV90IGkgPSAwOyBpIDwgc3RkOjpudW1lcmljX2xpbWl0czxzdGQ6OmludDY0X3Q+OjpkaWdpdHM7IGkrKyl7CgkJaWYgKChOJigoMXVsbCA8PCBpKSkpPjApIEMrKzsKCX0KCglyZXR1cm4gQzsKfQoKc3RkOjpzdHJpbmcgbHRvc3RyKHN0ZDo6aW50NjRfdCBOKXsKCXN0ZDo6c3RyaW5n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