1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <string> #include <iostream> #include <algorithm> std::string convert(unsigned long value, unsigned long base) { std::string rc; do { rc.push_back("0123456789abcde"[value % base]); } while (value /= base); std::reverse(rc.begin(), rc.end()); return rc; } int main() { std::cout << convert(100, 16) << '\n'; std::cout << convert(100, 10) << '\n'; std::cout << convert(100, 2) << '\n'; std::cout << convert(100, 1) << '\n'; } |
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKc3RkOjpzdHJpbmcgY29udmVydCh1bnNpZ25lZCBsb25nIHZhbHVlLCB1bnNpZ25lZCBsb25nIGJhc2UpIHsKICAgIHN0ZDo6c3RyaW5nIHJjOwogICAgZG8gewogICAgICAgIHJjLnB1c2hfYmFjaygiMDEyMzQ1Njc4OWFiY2RlIlt2YWx1ZSAlIGJhc2VdKTsKICAgIH0gd2hpbGUgKHZhbHVlIC89IGJhc2UpOwogICAgc3RkOjpyZXZlcnNlKHJjLmJlZ2luKCksIHJjLmVuZCgpKTsKICAgIHJldHVybiByYzsKfQoKaW50IG1haW4oKSB7CiAgICBzdGQ6OmNvdXQgPDwgY29udmVydCgxMDAsIDE2KSA8PCAnXG4nOwogICAgc3RkOjpjb3V0IDw8IGNvbnZlcnQoMTAwLCAxMCkgPDwgJ1xuJzsKICAgIHN0ZDo6Y291dCA8PCBjb252ZXJ0KDEwMCwgMikgPDwgJ1xuJzsKICAgIHN0ZDo6Y291dCA8PCBjb252ZXJ0KDEwMCwgMSkgPDwgJ1xuJzsKfQ==
-
upload with new input
-
result: Runtime error time: 3.82s memory: 135040 kB signal: 6 (SIGABRT)
64 100 1100100
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc


