#include <iostream>
using namespace std;
int main() {
string sCurrentTime;
time_t ltime;
struct tm *newtime;
char locTime[8 + 1];
time(<ime);
newtime = localtime(<ime);
sprintf(locTime, "%04d%02d%02d", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday); // YYYYMMDD
sCurrentTime = locTime;
std::string yydd = "5056";
unsigned short day = 0;
unsigned short month = 1;
unsigned short days_in_month[12] = {31, (unsigned short)((stoi(sCurrentTime.substr(0, 3) + yddd[0]) % 4) == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int i=0; i<12; i++) {
if (day - days_in_month[i] <= 0) {
break;
} else {
month++;
day -= days_in_month[i];
}
}
string yyyymmdd = sCurrentTime.substr(0,3) + yddd[0] + ((month < 10) ? "0" + toString<unsigned short>(month) : toString<unsigned short>(month)) + ((day < 10) ? "0" + toString<unsigned short>(day) : toString<unsigned short>(day));
std::cout << yyyymmdd;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglzdHJpbmcgc0N1cnJlbnRUaW1lOwogICAgICAgdGltZV90IGx0aW1lOwogICAgICBzdHJ1Y3QgdG0gKm5ld3RpbWU7CiAgICAgIGNoYXIgbG9jVGltZVs4ICsgMV07CiAgICAgIHRpbWUoJmx0aW1lKTsKICAgICAgbmV3dGltZSA9IGxvY2FsdGltZSgmbHRpbWUpOwogICAgICBzcHJpbnRmKGxvY1RpbWUsICIlMDRkJTAyZCUwMmQiLCBuZXd0aW1lLT50bV95ZWFyKzE5MDAsIG5ld3RpbWUtPnRtX21vbisxLCBuZXd0aW1lLT50bV9tZGF5KTsgLy8gWVlZWU1NREQKICAgICAgc0N1cnJlbnRUaW1lID0gbG9jVGltZTsKICAgIAogIHN0ZDo6c3RyaW5nIHl5ZGQgPSAiNTA1NiI7CiAgdW5zaWduZWQgc2hvcnQgZGF5ID0gMDsKICB1bnNpZ25lZCBzaG9ydCBtb250aCA9IDE7CiAgdW5zaWduZWQgc2hvcnQgZGF5c19pbl9tb250aFsxMl0gPSB7MzEsICh1bnNpZ25lZCBzaG9ydCkoKHN0b2koc0N1cnJlbnRUaW1lLnN1YnN0cigwLCAzKSArIHlkZGRbMF0pICUgNCkgPT0gMCA/IDI5IDogMjgpLCAzMSwgMzAsIDMxLCAzMCwgMzEsIDMxLCAzMCwgMzEsIDMwLCAzMX07CgogIGZvciAoaW50IGk9MDsgaTwxMjsgaSsrKSB7CiAgICBpZiAoZGF5IC0gZGF5c19pbl9tb250aFtpXSA8PSAwKSB7CiAgICAgIGJyZWFrOwogICAgfSBlbHNlIHsKICAgICAgbW9udGgrKzsKICAgICAgZGF5IC09IGRheXNfaW5fbW9udGhbaV07CiAgICB9CiAgfQogIHN0cmluZyB5eXl5bW1kZCA9IHNDdXJyZW50VGltZS5zdWJzdHIoMCwzKSArIHlkZGRbMF0gKyAoKG1vbnRoIDwgMTApID8gIjAiICsgdG9TdHJpbmc8dW5zaWduZWQgc2hvcnQ+KG1vbnRoKSA6IHRvU3RyaW5nPHVuc2lnbmVkIHNob3J0Pihtb250aCkpICsgKChkYXkgPCAxMCkgPyAiMCIgKyB0b1N0cmluZzx1bnNpZ25lZCBzaG9ydD4oZGF5KSA6IHRvU3RyaW5nPHVuc2lnbmVkIHNob3J0PihkYXkpKTsKCiAgc3RkOjpjb3V0IDw8IHl5eXltbWRkOwp9
prog.cpp: In function 'int main()':
prog.cpp:11:98: error: 'sprintf' was not declared in this scope
sprintf(locTime, "%04d%02d%02d", newtime->tm_year+1900, newtime->tm_mon+1, newtime->tm_mday); // YYYYMMDD
^
prog.cpp:17:94: error: 'yddd' was not declared in this scope
unsigned short days_in_month[12] = {31, (unsigned short)((stoi(sCurrentTime.substr(0, 3) + yddd[0]) % 4) == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
^
prog.cpp:17:101: error: 'stoi' was not declared in this scope
unsigned short days_in_month[12] = {31, (unsigned short)((stoi(sCurrentTime.substr(0, 3) + yddd[0]) % 4) == 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
^
prog.cpp:27:80: error: 'toString' was not declared in this scope
string yyyymmdd = sCurrentTime.substr(0,3) + yddd[0] + ((month < 10) ? "0" + toString<unsigned short>(month) : toString<unsigned short>(month)) + ((day < 10) ? "0" + toString<unsigned short>(day) : toString<unsigned short>(day));
^
prog.cpp:27:89: error: expected primary-expression before 'unsigned'
string yyyymmdd = sCurrentTime.substr(0,3) + yddd[0] + ((month < 10) ? "0" + toString<unsigned short>(month) : toString<unsigned short>(month)) + ((day < 10) ? "0" + toString<unsigned short>(day) : toString<unsigned short>(day));
^
prog.cpp:27:89: error: expected ':' before 'unsigned'
prog.cpp:27:89: error: expected primary-expression before 'unsigned'
prog.cpp:27:89: error: expected ')' before 'unsigned'