文章

221

粉丝

0

获赞

874

访问

32.7k

头像
日期计算 题解:
P1051 中南大学机试题
发布于2026年1月30日 22:31
阅读数 199

#include<iostream>
using namespace std;

int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int check(int year)
{
	if(year%4==0&&year&100!=0||year%400==0)
		return 1;
	return 0;
}

int main()
{
	int year,month,day;
	while(cin>>year>>month>>day)
	{
		int t=check(year);
		days[2]=28+t;
		if(month==0||month>12)
			cout<<"Input error!"<<endl;
		else if(day==0||day>days[month])
			cout<<"Input error!"<<endl;
		else
		{
			int res=0;
			for(int i=1;i<=month-1;i++)
				res+=days[i];
			res+=day;
			cout<<res<<endl;
		}
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发