AcWing 1229. 日期问题
原题链接
简单
作者:
滴水拓鲛珠
,
2024-02-13 20:06:31
,
所有人可见
,
阅读 40
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String in = scanner.next();
String []num = in.split("/");
int a = Integer.parseInt(num[0]);
int b = Integer.parseInt(num[1]);
int c = Integer.parseInt(num[2]);
for(int i = 19600101; i <= 20591231; i++)
{ int year = i / 10000;
int month = i / 100 % 100;
int day = i % 100;
if(check(year, month, day))
{ int t = year % 100;
if(t == a && month == b && day == c ||
month == a && day == b && t == c ||
day == a && month == b && t == c)
System.out.printf("%d-%02d-%02d\n", year, month, day);
}
}
}
public static int []days = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
public static boolean check(int year, int month, int day)
{ if(month > 12 || month == 0)
return false;
days[2] = (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) ? 29 : 28;
if(day == 0 || day > days[month])
return false;
return true;
}
}