模拟
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) throws Exception {
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
String s[]=sc.readLine().split("/");
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
int c=Integer.parseInt(s[2]);
String s1="";
String s2="";
String s3="";
if(a<60) s1="20"+s[0]+"-"+s[1]+"-"+s[2];
else s1="19"+s[0]+"-"+s[1]+"-"+s[2];
if(c<60){
s2="20"+s[2]+"-"+s[0]+"-"+s[1];
s3="20"+s[2]+"-"+s[1]+"-"+s[0];
}
else {
s2="19"+s[2]+"-"+s[0]+"-"+s[1];
s3="19"+s[2]+"-"+s[1]+"-"+s[0];
}
boolean f1=false,f2=false,f3=false;
Set<String> sum=new TreeSet<>();
sum.add(s1);
sum.add(s2);
sum.add(s3);
if(b>=1&&b<=12&&check(a,b,c)) f1=true;
if(a>=1&&a<=12&&check(c,a,b)) f2=true;
if(b>=1&&b<=12&&check(c,b,a)) f3=true;
for(String t:sum){
if(t.equals(s1)&&f1) System.out.println(t);
else if(t.equals(s2)&&f2) System.out.println(t);
else if(t.equals(s3)&&f3) System.out.println(t);
}
}
static int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
static boolean check(int year,int mouth,int day){
if(year<60) year+=2000;
else year+=1900;
if(mouth!=2) if(day<1||day>days[mouth]) return false;
if(mouth==2){
int append=0;
if(year%400==0||(year%100!=0&&year%4==0)) append=1;
if(day>days[mouth]+append) return false;
}
return true;
}
}
枚举
import java.io.*;
public class Main{
public static void main(String[] args) throws Exception {
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
String s[]=sc.readLine().split("/");
sc.close();
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
int c=Integer.parseInt(s[2]);
for(int i=19600101;i<=20591231;i++){
int year=i/10000, mouth=i%10000/100,day=i%100;
if(check(year,mouth,day)) {
if(((year%100)==a&&mouth==b&&day==c)||
((year%100)==c&&mouth==a&&day==b)||
((year%100)==c&&mouth==b&&day==a))
System.out.printf("%02d-%02d-%02d\n",year,mouth,day);
}
}
}
static int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
static boolean check(int year,int mouth,int day){
if(mouth<1||mouth>12) return false;
if(day<1) return false;
if(mouth!=2){
if(day>days[mouth]) return false;
}else{
int leap=0;
if(year%400==0||(year%100!=0&&year%4==0)) leap=1;
if(day>days[mouth]+leap) return false;
}
return true;
}
}