枚举日期范围判断是否合法,合法就看看否是符合三种组合要求
import java.util.*;
public class Main {
static int[] days = {0, 31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] s = sc.nextLine().split("/");
int a = toInt(s[0]), b = toInt(s[1]), c = toInt(s[2]);
for (int i = 19600101; i <= 20581231; i++) {
int year = i / 10000, mouth = i % 10000 / 100, day = i % 100;
if (cheek(year, mouth, day)) {
if (year % 100 == a && mouth == b && day == c || mouth == a && day == b && year % 100 == c || day == a && mouth == b && year % 100 == c) {
System.out.printf("%d-%02d-%02d\n", year, mouth, day);
//%02d占2位不足高位补0
}
}
}
}
static boolean cheek(int year, int mouth, int day) {
if (mouth > 12 || mouth == 0) return false;
if (day == 0) return false;
if (mouth != 2 && day > days[mouth]) return false;
if (mouth == 2) {
boolean flag = year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
int t = flag ? 29 : 28;
if (day > t) return false;
}
return true;
}
static int toInt(String s) {
return Integer.parseInt(s);
}
}