#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
int dayInMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string toString(int x, int len){
string res;
for(int i = 1; i <= len; i++){
res = (char) (x % 10 + '0') + res;
x /= 10;
}
return res;
}
struct date{
int d, m, y;
date(int _d = 0, int _m = 0, int _y = 0){
d = _d;
m = _m;
y = _y;
}
date(string &s){
d = (s[0] - '0') * 10 + (s[1] - '0');
m = (s[3] - '0') * 10 + (s[4] - '0');
y = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');
}
bool leapYear(){
return (y % 4 == 0);
}
bool isValid(){
if (d < 1 || m < 1 || 12 < m)
return 0;
if (m != 2 && d <= dayInMonth[m])
return 1;
if (d <= dayInMonth[2] + leapYear())
return 1;
return 0;
}
bool isPalindromic(){
string s = toString(d, 2) + toString(m, 2) + toString(y, 4);
string revS = s;
reverse(revS.begin(), revS.end());
return (s == revS);
}
bool check(){
return (isValid() && isPalindromic());
}
void print(){
cout << toString(d, 2) << '.' << toString(m, 2) << '.' << toString(y, 4) << ".\n";
}
};
bool operator < (const date &a, const date &b){
if (a.y != b.y)
return a.y < b.y;
if (a.m != b.m)
return a.m < b.m;
return a.d < b.d;
}
int n;
vector <date> palinromicDays;
void readInput(){
scanf("%d", &n);
}
void solve(){
for(int a = 0; a <= 3; a++)
for(int b = 0; b <= 9; b++)
for(int c = 0; c <= 1; c++)
for(int d = 0; d <= 9; d++){
date tmp(a * 10 + b, c * 10 + d, d * 1000 + c * 100 + b * 10 + a);
if (tmp.check())
palinromicDays.push_back(tmp);
}
sort(palinromicDays.begin(), palinromicDays.end());
while (n--){
string s;
cin >> s;
date q(s);
(*upper_bound(palinromicDays.begin(), palinromicDays.end(), q)).print();
}
}
int main(){
readInput();
solve();
return 0;
}
Compilation message
datum.cpp: In function 'void readInput()':
datum.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
69 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
30 ms |
484 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
34 ms |
508 KB |
Output is correct |