#include <iostream>
#include <map>
#include <algorithm>
int cntBits(int value) {
int num_bits=0;
for(size_t i = 0; i < 32 ; ++i, value >>= 1) {
if ((value & 1) == 1) ++num_bits;
}
return num_bits;
}
struct cntBitsCmp {
bool operator()(int a, int b) {
return cntBits(a) < cntBits(b);
}
};
using namespace std;
int main() {
std::map<int,int,cntBitsCmp> myMap = {
{128,2},
{3,4}
};
for(std::map<int,int,cntBitsCmp>::const_iterator i=myMap.begin() ; i != myMap.end() ; ++i) {
cout << i->first << " " << i->second << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKaW50IGNudEJpdHMoaW50IHZhbHVlKSB7CiAgICBpbnQgbnVtX2JpdHM9MDsKICAgIGZvcihzaXplX3QgaSA9IDA7IGkgPCAzMiA7ICsraSwgdmFsdWUgPj49IDEpIHsKICAgICAgICBpZiAoKHZhbHVlICYgMSkgPT0gMSkgKytudW1fYml0czsKICAgIH0KICAgIHJldHVybiBudW1fYml0czsKfQoKc3RydWN0IGNudEJpdHNDbXAgewogICAgYm9vbCBvcGVyYXRvcigpKGludCBhLCBpbnQgYikgewogICAgICAgIHJldHVybiBjbnRCaXRzKGEpIDwgY250Qml0cyhiKTsKICAgIH0KfTsKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCXN0ZDo6bWFwPGludCxpbnQsY250Qml0c0NtcD4gbXlNYXAgPSAgewogICAgICAgIHsxMjgsMn0sCiAgICAgICAgezMsNH0KICAgIH07CiAgICBmb3Ioc3RkOjptYXA8aW50LGludCxjbnRCaXRzQ21wPjo6Y29uc3RfaXRlcmF0b3IgaT1teU1hcC5iZWdpbigpIDsgaSAhPSBteU1hcC5lbmQoKSA7ICsraSkgewogICAgICAgIGNvdXQgPDwgaS0+Zmlyc3QgPDwgIiAiIDw8IGktPnNlY29uZCA8PCBlbmRsOwogICAgfQoJcmV0dXJuIDA7Cn0=