#include <iostream>
template<int W>
typename std::enable_if<(W<10), std::string>::type
to_number(int n){
char const fmt [] = {'%', W+'0', 'd', 0};
char buffer[20];
sprintf(buffer, fmt, n);
return buffer;
}
template<int W>
typename std::enable_if<(W>=10), std::string>::type
to_number(int n) {
char const fmt [] = {'%', (W/10)+'0', (W%10)+'0', 'd', 0};
char buffer[20];
sprintf(buffer, fmt, n);
return buffer;
}
int main() {
std::cout << to_number<5>(7) << '\n';
std::cout << to_number<15>(7);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8aW50IFc+CnR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPChXPDEwKSwgc3RkOjpzdHJpbmc+Ojp0eXBlIAp0b19udW1iZXIoaW50IG4pewoJY2hhciBjb25zdCBmbXQgW10gPSB7JyUnLCBXKycwJywgJ2QnLCAwfTsKCWNoYXIgYnVmZmVyWzIwXTsKCXNwcmludGYoYnVmZmVyLCBmbXQsIG4pOwoJcmV0dXJuIGJ1ZmZlcjsKfQp0ZW1wbGF0ZTxpbnQgVz4KdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8KFc+PTEwKSwgc3RkOjpzdHJpbmc+Ojp0eXBlCnRvX251bWJlcihpbnQgbikgewoJY2hhciBjb25zdCBmbXQgW10gPSB7JyUnLCAoVy8xMCkrJzAnLCAoVyUxMCkrJzAnLCAnZCcsIDB9OwoJY2hhciBidWZmZXJbMjBdOwoJc3ByaW50ZihidWZmZXIsIGZtdCwgbik7CglyZXR1cm4gYnVmZmVyOwp9CgppbnQgbWFpbigpIHsKCXN0ZDo6Y291dCA8PCB0b19udW1iZXI8NT4oNykgPDwgJ1xuJzsKCXN0ZDo6Y291dCA8PCB0b19udW1iZXI8MTU+KDcpOwoJcmV0dXJuIDA7Cn0=