AcWing 3214. 节日java
原题链接
中等
作者:
huaqingren
,
2021-02-26 17:47:58
,
所有人可见
,
阅读 320
import java.util.Calendar;
import java.util.Scanner;
public class Main
{
private static int[] calen= {0,31,28,31,30,31,30,31,31,30,31,30,31};
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
int c=scan.nextInt();
int y1=scan.nextInt();
int y2=scan.nextInt();
for(int i=y1;i<=y2;i++)
{
String str=judge(i,a,b,c);
System.out.println(str);
}
scan.close();
}
private static String judge(int year, int a, int b, int c)
{
if(year%400==0||(year%4==0&&year%100!=0))
calen[2]=29;
else
calen[2]=28;
//判断每年a月1号是周几
Calendar cal=Calendar.getInstance();
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH,a-1);
cal.set(Calendar.DAY_OF_MONTH,1);
int week = cal.get(Calendar.DAY_OF_WEEK);
if(week==1)
week=7;
else
week-=1;
week--;
if(week<1)
week=7;
//System.out.println(week);
int day=1;
int cnt=0;//记录下找到了几次c
for(day=1;day<=calen[a];day++)
{
week++;
if(week>7)
{
week=1;
}
if(week==c)
cnt++;
if(cnt==b)
break;
}
if(cnt!=b)
return "none";
return year+"/"+(a<10?"0"+a:a)+"/"+(day<10?"0"+day:day);
}
}