#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N=10005;
int const mod=1e9+7;
bool year[N];
int mon[N];
int dt[N];
int leaf(int y){
return (y%4==0);
}
bool check1(int y){
string yr=to_string(y);
while(yr.length()<4)
yr='0'+yr;
int d=((yr[3]-'0')*10)+(yr[2]-'0');
int m=((yr[1]-'0')*10)+(yr[0]-'0');
if(m>12 || m<=0 || d<=0 || d>31)
return 0;
int dm[13]={0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31};
dm[2]+=leaf(y);
if(d<=dm[m] && d>0){
mon[y]=m;
dt[y]=d;
return 1;
}
return 0;
}
void solve(){
string date;
cin>>date;
int y=((date[6]-'0')*1000)+((date[7]-'0')*100)+((date[8]-'0')*10)+(date[9]-'0');
int m=((date[3]-'0')*10)+(date[4]-'0');
int d=((date[0]-'0')*10)+(date[1]-'0');
int ans_y=9999;
// cout<<y<<endl;
// cout<<d<<' '<<m<<' '<<y<<endl;
if(year[y]){
// cout<<dt[y]<<' '<<mon[y]<<endl;
if(m<mon[y])
ans_y=y;
if(mon[y]==m && d<dt[y])
ans_y=y;
}
for(int i=y+1;i<=9999;i++)
if(year[i])
ans_y=min(i,ans_y);
string ay=to_string(ans_y);
while(ay.length()<4)
ay='0'+ay;
cout<<ay[3]<<ay[2]<<'.'<<ay[1]<<ay[0]<<'.'<<ay<<'.'<<endl;
// cout<<"----------------------"<<endl;
}
int main(){
for(int i=1;i<=9999;i++){
year[i]=check1(i);
// if(year[i])
// cout<<dt[i]<<'.'<<mon[i]<<'.'<<i<<endl;
}
int t=1;
cin>>t;
while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
70 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
69 ms |
560 KB |
Output is correct |