제출 #845259

#제출 시각아이디문제언어결과실행 시간메모리
845259vjudge1Datum (COCI20_datum)C++17
5 / 50
6 ms348 KiB
// author: erray #include <bits/stdc++.h> #ifdef DEBUG #include "debug.h" #else #define debug(...) void(37) #endif using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int TT; cin >> TT; while (TT--) { string D; cin >> D; int cur = 0, year = 0; auto C = [&](char c) { return c - '0'; }; cur = C(D[0]) + 10 * C(D[1]) + 100 * C(D[3]) + 1000 * C(D[4]); for (int i = 0, pw = 1; i < 4; ++i, pw *= 10) { year += pw * C(D.end()[-i - 2]); } debug(cur, year); auto Find = [&](int y) { auto Day = [&](int x) { int r = x % 100; return r % 10 * 10 + (r / 10); }; auto Month = [&](int x) { int r = x / 100; return r % 10 * 10 + (r / 10); }; auto Leap = [&](int x) { return x % 4 == 0; }; constexpr int days[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; auto Valid = [&](int x) { int m = Month(x); return m <= 12 && m > 0 && (days[m] + (m == 2 && Leap(x)) >= Day(x)); }; debug("here"); for (int add = 0; add < 100; ++add) { if (Valid(y + add)) { return y + add; } } debug("bad"); y -= y % 100; y += 1; while (Month(y) > 12 || Month(y) == 0) { y += 100; } debug(y); assert(Valid(y)); return y; //divisible by 4 but not 100 }; int ans = Find(year); if (ans == year && cur >= year) { ans = Find(year + 1); } debug(ans); string res; string yts = to_string(ans); while (yts.size() < 4) { yts.insert(yts.begin(), '0'); } debug(D, yts); res += yts; reverse(res.begin(), res.end()); res += yts; res.insert(res.begin() + 2, '.'); res.insert(res.begin() + 5, '.'); res.insert(res.end(), '.'); cout << res << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...