#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
vector<int> t{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int toInt(string s){
int ans=0, cur=1;
for(int i=s.size()-1; i>=0; i--){
ans+=cur*(s[i]-'0');
cur*=10;
}
return ans;
}
string toString4(int a){
string s;
for(int i=0; i<4; i++){
s.push_back((a%10)+'0');
a/=10;
}
reverse(all(s));
return s;
}
string toString2(int a){
string s;
for(int i=0; i<2; i++){
s.push_back((a%10)+'0');
a/=10;
}
reverse(all(s));
return s;
}
int isValid(int y){
string s=toString4(y);
int d=(s[3]-'0')*10+s[2]-'0', m=(s[1]-'0')*10+s[0]-'0';
if(d!=0 && m!=0 && m<=12 && d<=t[m] && (d!=29 || m!=2 || y%4==0)) return 1;
else return 0;
}
int main(){
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int d=(s[9]-'0')*10+s[8]-'0', m=(s[7]-'0')*10+s[6]-'0', y=toInt(string(s.begin()+6, s.begin()+10));
int dcur=(s[0]-'0')*10+s[1]-'0', mcur=(s[3]-'0')*10+s[4]-'0';
if(isValid(y) && (m>mcur || (m==mcur && d>dcur)))
cout<<toString2(d)<<'.'<<toString2(m)<<'.'<<toString4(y)<<'.'<<endl;
else{
for(int i=y+1; i<10'000; i++){
if(isValid(i)){
string ans=toString4(i);
cout<<ans[3]<<ans[2]<<'.'<<ans[1]<<ans[0]<<'.'<<ans<<'.'<<endl;
break;
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
91 ms |
452 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
89 ms |
472 KB |
Output is correct |