#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdint>
#include <limits>
//this result is who's bug??
int CountBit(std::int32_t N){
int C = 0;
for (std::size_t i = 0; i < std::numeric_limits<std::int32_t>::digits; i++){
if ((N&static_cast<std::int64_t>((1 << 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&static_cast<std::int64_t>(1 << (i-1))) == 0 && F == false) continue;
F = true;
str += C[(N&static_cast<std::int64_t>(1 << (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+CgovL3RoaXMgcmVzdWx0IGlzIHdobydzIGJ1Zz8/CgppbnQgQ291bnRCaXQoc3RkOjppbnQzMl90IE4pewoJaW50IEMgPSAwOwoKIAlmb3IgKHN0ZDo6c2l6ZV90IGkgPSAwOyBpIDwgc3RkOjpudW1lcmljX2xpbWl0czxzdGQ6OmludDMyX3Q+OjpkaWdpdHM7IGkrKyl7CgkJaWYgKChOJnN0YXRpY19jYXN0PHN0ZDo6aW50NjRfdD4oK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