C++实战之判断闰年

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_41279876/article/details/102470681

判断X年X月X日是该年的第几天

class Solution
{
public:
	bool isLeap(int year);
	
private:
	int year;
	int month;
	int day;
};
bool Solution::isLeap(int year)
{
	if (((year % 4==0) &&(year % 100!=0) )|| year % 400==0)
	{
		cout << "是润年" << endl;
		return true;
	}
	else
	{
		return false;
	}
}
int main()
{
	int year, month, day;
	cin >> year;
	cin >> month;
	cin >> day;
	Solution solution;
	int month_num[] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
	if (solution.isLeap(year))
	{
		month_num[1] = 29;
		
	}
	int res = 0;
	for (int i = 0; i < month-1; i++)
	{
		res += month_num[i];
	}
	res += day;
	cout << res;
	return 0;

}

猜你喜欢

转载自blog.csdn.net/weixin_41279876/article/details/102470681