#include <bits/stdc++.h>
using std::vector;
using std::array;
using std::tuple;
using std::pair;
int read(int len) {
int ret = 0;
while (len--) {
char c;
std::cin >> c;
ret = 10 * ret + (c - '0');
}
return ret;
}
void ignore() {
char c;
std::cin >> c;
}
constexpr int memo[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
int N;
std::cin >> N;
vector<tuple<int, int, int>> good;
for (int a = 0; a < 10; ++a) {
for (int b = 0; b < 10; ++b) {
for (int c = 0; c < 10; ++c) {
for (int d = 0; d < 10; ++d) {
int year = 1000 * a + 100 * b + 10 * c + 1 * d;
int day = 10 * d + 1 * c;
int month = 10 * b + 1 * a;
if (month < 1 or 12 < month) {
continue;
}
if (day < 1 or memo[month - 1] + (year % 4 == 0 and month == 2) < day) {
continue;
}
good.emplace_back(year, month, day);
}
}
}
}
while (N--) {
int day = read(2);
ignore();
int month = read(2);
ignore();
int year = read(4);
ignore();
const auto [y, m, d] = *std::upper_bound(good.begin(), good.end(), std::make_tuple(year, month, day));
std::cout << std::setw(2) << std::setfill('0') << d << '.';
std::cout << std::setw(2) << std::setfill('0') << m << '.';
std::cout << std::setw(4) << std::setfill('0') << y << ".\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
21 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
21 ms |
528 KB |
Output is correct |