#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
// char ss[100];
bool pal(string a){
int n = a.size();
for(int i = 0;i < 8;i ++){
if(a[i] != a[n - i - 1])return false;
}
return true;
}
bool cmp(string a, string b){
int dd1 = (a[0] - '0') * 10 + (a[1] - '0');
int mm1 = (a[3] - '0') * 10 + (a[4] - '0');
int yy1 = (a[6] - '0') * 1000 + (a[7] - '0') * 100 + (a[8] - '0') * 10 + (a[9] - '0');
int dd2 = (b[0] - '0') * 10 + (b[1] - '0');
int mm2 = (b[3] - '0') * 10 + (b[4] - '0');
int yy2 = (b[6] - '0') * 1000 + (b[7] - '0') * 100 + (b[8] - '0') * 10 + (b[9] - '0');
if(yy1 == yy2){
if(mm1 == mm2)return dd1 < dd2;
return mm1 < mm2;
}
return yy1 < yy2;
}
int m1[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m2[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool valid(string a, bool leap){
int dd = (a[0] - '0') * 10 + (a[1] - '0');
int mm = (a[2] - '0') * 10 + (a[3] - '0');
// cerr << "dd : " << dd << " " << "mm : " << mm << '\n';
if(leap){
if(mm > 0 and mm <= 12 and dd > 0 and dd <= m2[mm - 1])return true;
} else {
if(mm > 0 and mm <= 12 and dd > 0 and dd <= m1[mm - 1])return true;
}
return false;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int tt;
cin >> tt;
while(tt --){
string s;
cin >> s;
int dd = (s[0] - '0') * 10 + (s[1] - '0');
int mm = (s[3] - '0') * 10 + (s[4] - '0');
int yy = (s[6] - '0') * 1000 + (s[7] - '0') * 100 + (s[8] - '0') * 10 + (s[9] - '0');
for(;yy <= 9999;yy ++){
stringstream ss;
ss << (yy / 1000) % 10 << (yy / 100) % 10 << (yy / 10) % 10 << yy % 10;
string S = ss.str();
reverse(all(S));
if(valid(S, yy % 4 == 0)){
stringstream ans;
ans << S[0] << S[1] << '.' << S[2] << S[3] << '.' << (yy / 1000) % 10 << (yy / 100) % 10 << (yy / 10) % 10 << yy % 10 << '.';
if(cmp(s, ans.str())){
cout << ans.str() << '\n';
break;
}
}
// for(int i = mm;i <= 12;i ++){
// bool done = false;
// for(int j = ((i == mm)?dd:1);j <= ((yy % 4 == 0)?m2[i - 1]:m1[i - 1]);j ++){
// stringstream ss;
// ss << j / 10 << j % 10 << i / 10 << i % 10 << (yy / 1000) % 10 << (yy / 100) % 10 << (yy / 10) % 10 << yy % 10;
// // cerr << ss.str() << '\n';
// if(pal(ss.str())){
// // cerr << "yes";
// done = true;
// stringstream ans;
// ans << j / 10 << j % 10 << '.' << i / 10 << i % 10 << '.' << (yy / 1000) % 10 << (yy / 100) % 10 << (yy / 10) % 10 << yy % 10 << '.';
// cout << ans.str() << '\n';
// break;
// }
// }
// if(done)break;
// }
}
// for(int i = dd + 1;i <= 31;i ++){
// }
}
return 0;
}
Compilation message
datum.cpp: In function 'int main()':
datum.cpp:53:7: warning: unused variable 'dd' [-Wunused-variable]
53 | int dd = (s[0] - '0') * 10 + (s[1] - '0');
| ^~
datum.cpp:54:7: warning: unused variable 'mm' [-Wunused-variable]
54 | int mm = (s[3] - '0') * 10 + (s[4] - '0');
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Execution timed out |
1079 ms |
528 KB |
Time limit exceeded |
3 |
Correct |
1 ms |
268 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
3 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
4 ms |
364 KB |
Output is correct |
9 |
Correct |
4 ms |
364 KB |
Output is correct |
10 |
Execution timed out |
1078 ms |
492 KB |
Time limit exceeded |