AcWing 1229. 日期问题
原题链接
简单
作者:
你也叫依古比古吗
,
2020-09-12 16:35:45
,
所有人可见
,
阅读 521
#include<bits/stdc++.h>
using namespace std;
int a1,a2,a3;
int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(int date)
{
int year = date / 10000;
int month = date % 10000 / 100;
int day = date % 100;
if (!month || month > 13 || !day) return false;
if (month != 2 && day > months[month]) return false;
if (month == 2)
{
bool leap = year % 4 == 0 && year % 100 || year % 400 == 0;
if (day > 28 + leap) return false;
}
return true;
}
int main()
{
scanf("%d/%d/%d",&a1,&a2,&a3);
for(int i = 19600101;i <= 20591231;i++)
{
int y = i / 10000,m = i % 10000 / 100,d = i % 100;
if(check(i))//合法的日期
{
if(y % 100 == a1 && m == a2 && d == a3//三种情况,年月日,月日年,日月年
|| m == a1 && d == a2 && y % 100 == a3
|| d == a1 && m == a2 && y % 100 == a3)
printf("%d-%02d-%02d\n",y,m,d);
}
}
return 0;
}