求助,70分
查看原帖
求助,70分
872146
ZZJM楼主2023/7/18 17:54
#include<iostream>
#include<string>
using namespace std;

bool isPalindrome(string str)//判断是否是回文数
{
	int left = 0;
	int right = str.size() - 1;
	while (left < right)
	{
		if (str[left++] != str[right--])
		{
			return false;
		}
	}
	return true;
}
int main()
{
	int day1[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	int count = 0;
	int des1, des2;
	cin >> des1 >> des2;

	for (int i = des1; i <= des2; i++)
	{
		int year = i / 10000;
		int month = (i / 100) % 100;
		int day = i % 100;
		if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
		{
			day1[1]++;
		}
		if (month > 12 || month == 0)
		{
			continue;
		}
		if (day1[month-1] < day || day == 0)
		{
			continue;
		}
		string str = to_string(i);
		if (isPalindrome(str))
		{
			count++;
		}
		day1[1]--;
	}

	cout << count;
	return 0;
}
2023/7/18 17:54
加载中...