# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
845270 | vjudge1 | Datum (COCI20_datum) | C++17 | 4 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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);
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;
};
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) {
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 && array<int, 2>{Month(year), Day(year)} <= array<int, 2>{cur / 100, cur % 100}) {
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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |