# 2021蓝桥杯大赛软件类国赛Java大学B组 完全日期 复杂遍历搜索

``````package Dduo;

public class Main {
public static void main(String[] args) {
int cnt=0;
int arr[]=new int[] {0,31,28,31,30,31,30,31,31,30,31,30,31};

int day=1;
int month=1;
int year=2001;
for(;;day++) {
if(day>arr[month]) {
day=1;
month++;
}
if(month>12) {
month=1;
day=1;
year++;
}
if(year==2022&&month==1&&day==1)break;
if(judge(sum(year)+sum(month)+sum(day))) {
System.out.println(year+" "+month+" "+day);
cnt++;
}
}
//单独判断闰年
if(judge(sum(2004)+sum(2)+sum(29))) {
System.out.println(year+" "+month+" "+day);
cnt++;
}
if(judge(sum(2008)+sum(2)+sum(29))) {
System.out.println(year+" "+month+" "+day);
cnt++;
}
if(judge(sum(2012)+sum(2)+sum(29))) {
System.out.println(year+" "+month+" "+day);
cnt++;
}
if(judge(sum(2016)+sum(2)+sum(29))) {
System.out.println(year+" "+month+" "+day);
cnt++;
}
if(judge(sum(2020)+sum(2)+sum(29))) {
System.out.println(year+" "+month+" "+day);
cnt++;
}
System.out.print(cnt);
}
public static int sum(int x) {
int sum=0;
while(x>0) {
sum+=x%10;
x/=10;
}
return sum;
}
public static boolean  judge(int x) {
int ans=(int )Math.sqrt(x);
if(ans*ans==x)return true;
else return false;
}
}``````

THE END