顺着日期
public class Main {public static void main(String[] args) {int res = 0;//2022年int[] days = new int[] {31,28,31,30,31,30,31,31,30,31,30,31};//31,28,31,30,31,30,31,31,30,31,30,31//一三五七八十腊//构造2022年每一天的日期yyyymmddStringBuffer date = new StringBuffer("2022");for(int m=1;m<=12;m++) {if(m<10) {date.append(0);}date.append(m);for(int d=1;d<=days[m-1];d++) {if(d<10) {date.append(0);}date.append(d);if(isLegal(date.toString())) {res++;}date.delete(6, 8);//20220101 -> 202201}date.delete(4, 8);//202201 -> 2022}System.out.println(res);}public static boolean isLegal(String date) {//20220101//202201int l = 0;int n = date.length();while(l<=n-3) {int t1 = (int)Integer.valueOf(date.substring(l,l+1));//2int t2 = (int)Integer.valueOf(date.substring(l+1,l+2));//0int t3 = (int)Integer.valueOf(date.substring(l+2,l+3));//2if(t1 == (t2-1) && t2 == (t3-1)) {return true;}l++;}return false;}
}