洛谷P8716 [蓝桥杯 2020 省 AB2] 回文日期

题目链接:P8716 [蓝桥杯 2020 省 AB2] 回文日期 - 洛谷

通俗易懂,暴力即可

#include 
using namespace std;
int n;
bool flag=0;
int da[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
bool check(int x)
{
	if (x % 400 == 0 || (x % 4 == 0 && x % 100 != 0)) return 1;
	return 0;
}
int main()
{
	cin >> n;
	for (int i = n + 1;i <= 99999999;i++)
	{
		int a, b, c, d, e, f, g, h, year, month, dat;
		a = i % 10;//个位
		b = (i / 10) % 10;//十位
		c = (i / 100) % 10;
		d = (i / 1000) % 10;
		e = (i / 10000) % 10;
		f = (i / 100000) % 10;
		g = (i / 1000000) % 10;
		h = i / 10000000;
		year = i / 10000;
		month = d * 10 + c;
		dat = b * 10 + a;
		if (check(year)) da[2] = 29;
		else da[2] = 28;
		if (month <= 12 && dat <= da[month] && h == a && b == g && c == f && d == e && flag == 0)
		{
			cout << i << '\n';
			flag = 1;
		}
		if (month <= 12 && dat <= da[month] && h == a && b == g && h == c && c == f && g == b && d == g&&e==d&&flag)
		{
			cout << i;
			break;
		}
	}
	return 0;
}

你可能感兴趣的:(蓝桥杯,c++,算法,数据结构)