该题较为简单,不过要注意申清题目之后再动手,不然就和我一开始一样了(以为被20120312整除)
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <iomanip>
#include<cmath>
#include<cstring>
using namespace std;
int check(int n)//检查能否符合8位年月日
{
int year = n / 10000;
int month = ((n / 1000) % 10) * 10 + (n / 100) % 10;
int day = ((n / 10) % 10) * 10 + n % 10;
int leap = (n % 4 == 0 && n % 100 != 0) || (n % 400 == 0);
int m[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
if (leap)
{
m[2] = 29;
}
if (day >= 0 && day <= m[month] && month >= 1 && month <= 12)
{
return 1;
}
return 0;
}
int main()
{
for (int i = 19000000; i < 20220000; i++)
{
if ( i %2012 == 0&& i%6==0 && i%12==0&&check(i))
{
cout << i << endl;
}
}
return 0;
}