ZOJ 1256 What Day Is It?(有点坑)

What Day Is It?

Time Limit: 2000 msMemory Limit: 65536 KB The calendar now in use
evolved from the Romans. Julius Caesar codified a calendar system that
came to be known as the Julian calendar. In this system, all months
have 31 days, except for April, June, September, and November, which
have 30 days, and February, which has 28 days in non-leap years, and
29 days in leap years. Also, in this system, leap years happened every
four years. That is because the astronomers of ancient Rome computed
the year to be 365.25 days long, so that after every four years, one
needed to add an extra day to keep the calendar on track with the
seasons. To do this, they added an extra day (February 29) to every
year that was a multiple of four. Julian Rule:

Every year that is a multiple of 4 is a leap year, i.e. has an extra
day (February 29).

In 1582, Pope Gregory’s astronomers noticed that the year was not
365.25 days long, but closer to 365.2425. Therefore, the leap year rule would be revised to the following:

Gregorian Rule:

Every year that is a multiple of 4 is a leap year, unless it is a
multiple of 100 that is not a multiple of 400.

To compensate for how the seasons had shifted against the calendar up
until that time, the calendar was actually shifted 10 days: the day
following October 4, 1582 was declared to be October 15.

England and its empire (including the United States) didn’t switch to
the Gregorian calendar system until 1752, when the day following
September 2 was declared to be September 14. (The delay was caused by
the poor relationship between Henry VIII and the Pope.)

Write a program that converts dates in the United States using a
calendar of the time and outputs weekdays.

Input

The input will be a series of positive integers greater than zero,
three integers per line, which represent dates, one date per line. The
format for a date is ``month day year" where month is a number between
1 (which indicates January) and 12 (which indicates December), day is
a number between 1 and 31, and year is positive number.

Output

The output will be the input date and name of the weekday on which the
given date falls in the format shown in the sample. An invalid date or
nonexistent date for the calendar used in the United States at the
time should generate an error message indicating a invalid date. The
input will end with three zeroes.

Sample Input

11 15 1997
1 1 2000
7 4 1998
2 11 1732
9 2 1752
9 14 1752
4 33 1997
0 0 0

Sample Output

November 15, 1997 is a Saturday
January 1, 2000 is a Saturday
July 4, 1998 is a Saturday
February 11, 1732 is a Friday
September 2, 1752 is a Wednesday
September 14, 1752 is a Thursday
4/33/1997 is an invalid date.

思路:

题目大意是说在1752年9月2日前美国采用的是Julius历,每四年闰一次,而在这天之后为了历法的精确性,将9月3号改成了9月14号,之后给出一些年月日的样例,要求输出当天是星期几。
思路就是算出从公元元年的1月1号起到当前的日期一共有多少天,然后对7取余即可。主要是要注意闰年规则的变化!!!

AC代码:

#include<iostream>
#include<queue>

using namespace std;
int days[] = { 0, 31,28,31,30,31,30,31,31,30,31,30,31 };
int year[100001];
int y, m, d;

bool isOld(int year,int month,int day)
{
	return year < 1752 || (year == 1752 && month < 9) || (year == 1752 && month == 9 && day <= 2);
}

bool isLeap(int year, bool old)
{
	if (old)
		return year % 4 == 0;
	else
		return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}

bool judge(int y, int m, int d)
{
	if (y == 1752 && m == 9 && 3 <= d && d <= 13)
		return false;
	if (y > 0 && 1 <= m && m <= 12)
	{
		if (isLeap(y, isOld(y, 1, 1)))
			days[2] = 29;
		return 1 <= d && d <= days[m];
	}
	return false;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int i;
	int sum = 0;
	int weeks;
	bool old;
	for (i = 1; i <= 9999; ++i)
	{
		if (i == 1752)
			year[i] = year[i - 1] + 355;
		else if (isLeap(i, isOld(i, 1, 1)))
			year[i] = year[i - 1] + 366;
		else
			year[i] = year[i - 1] + 365;
	}
	while (cin >> m >> d >> y, m != 0 || d != 0 || y != 0)
	{
		days[2] = 28; days[9] = 30;
		if (!judge(y, m, d))
		{
			cout << m << "/" << d << "/" << y << " is an invalid date." << endl;
			continue;
		}
		old = isOld(y, m, d);
		switch (m)
		{
		case 1:
			cout << "January " << d << ", " << y;
			break;
		case 2:
			cout << "February " << d << ", " << y;
			break;
		case 3:
			cout << "March " << d << ", " << y;
			break;
		case 4:
			cout << "April " << d << ", " << y;
			break;
		case 5:
			cout << "May " << d << ", " << y;
			break;
		case 6:
			cout << "June " << d << ", " << y;
			break;
		case 7:
			cout << "July " << d << ", " << y;
			break;
		case 8:
			cout << "August " << d << ", " << y;
			break;
		case 9:
			cout << "September " << d << ", " << y;
			break;
		case 10:
			cout << "October " << d << ", " << y;
			break;
		case 11:
			cout << "November " << d << ", " << y;
			break;
		case 12:
			cout << "December " << d << ", " << y;
			break;
		}
		sum = 0;
		sum = year[y - 1];
		if (isLeap(y, old))days[2] = 29;
		if (y == 1752)days[9] = 19;
		for (i = 1; i < m; ++i)sum += days[i];
		if (y == 1752 && m == 9 && d >= 14)
			sum = sum + (d - 11);
		else 
			sum += d;
		weeks = sum % 7;
		switch (weeks)
		{
		case 0:
			cout << " is a Friday" << endl;
			break;
		case 1:
			cout << " is a Saturday" << endl;
			break;
		case 2:
			cout << " is a Sunday" << endl;
			break;
		case 3:
			cout << " is a Monday" << endl;
			break;
		case 4:
			cout << " is a Tuesday" << endl;
			break;
		case 5:
			cout << " is a Wednesday" << endl;
			break;
		case 6:
			cout << " is a Thursday" << endl;
			break;
		}
	}
	return 0;
}
智慧旅游解决方案利用云计算、物联网和移动互联网技术,通过便携终端设备,实现对旅游资源、经济、活动和旅游者信息的智能感知和发布。这种技术的应用旨在提升游客在旅游各个环节的体验,使他们能够轻松获取信息、规划行程、预订票务和安排食宿。智慧旅游平台为旅游管理部门、企业和游客提供服务,包括政策发布、行政管理、景区安全、游客流量统计分析、投诉反馈等。此外,平台还提供广告促销、库存信息、景点介绍、电子门票、社交互动等功能。 智慧旅游的建设规划得到了国家政策的支持,如《国家中长期科技发展规划纲要》和国务院的《关于加快发展旅游业的意见》,这些政策强调了旅游信息服务平台的建设和信息化服务的重要性。随着技术的成熟和政策环境的优化,智慧旅游的时机已经到来。 智慧旅游平台采用SaaS、PaaS和IaaS等云服务模式,提供简化的软件开发、测试和部署环境,实现资源的按需配置和快速部署。这些服务模式支持旅游企业、消费者和管理部门开发高性能、高可扩展的应用服务。平台还整合了旅游信息资源,提供了丰富的旅游产品创意平台和统一的旅游综合信息库。 智慧旅游融合应用面向游客和景区景点主管机构,提供无线城市门户、智能导游、智能门票及优惠券、景区综合安防、车辆及停车场管理等服务。这些应用通过物联网和云计算技术,实现了旅游服务的智能化、个性化和协同化,提高了旅游服务的自由度和信息共享的动态性。 智慧旅游的发展标志着旅游信息化建设的智能化和应用多样化趋势,多种技术和应用交叉渗透至旅游行业的各个方面,预示着全面的智慧旅游时代已经到来。智慧旅游不仅提升了游客的旅游体验,也为旅游管理和服务提供了高效的技术支持。
智慧旅游解决方案利用云计算、物联网和移动互联网技术,通过便携终端设备,实现对旅游资源、经济、活动和旅游者信息的智能感知和发布。这种技术的应用旨在提升游客在旅游各个环节的体验,使他们能够轻松获取信息、规划行程、预订票务和安排食宿。智慧旅游平台为旅游管理部门、企业和游客提供服务,包括政策发布、行政管理、景区安全、游客流量统计分析、投诉反馈等。此外,平台还提供广告促销、库存信息、景点介绍、电子门票、社交互动等功能。 智慧旅游的建设规划得到了国家政策的支持,如《国家中长期科技发展规划纲要》和国务院的《关于加快发展旅游业的意见》,这些政策强调了旅游信息服务平台的建设和信息化服务的重要性。随着技术的成熟和政策环境的优化,智慧旅游的时机已经到来。 智慧旅游平台采用SaaS、PaaS和IaaS等云服务模式,提供简化的软件开发、测试和部署环境,实现资源的按需配置和快速部署。这些服务模式支持旅游企业、消费者和管理部门开发高性能、高可扩展的应用服务。平台还整合了旅游信息资源,提供了丰富的旅游产品创意平台和统一的旅游综合信息库。 智慧旅游融合应用面向游客和景区景点主管机构,提供无线城市门户、智能导游、智能门票及优惠券、景区综合安防、车辆及停车场管理等服务。这些应用通过物联网和云计算技术,实现了旅游服务的智能化、个性化和协同化,提高了旅游服务的自由度和信息共享的动态性。 智慧旅游的发展标志着旅游信息化建设的智能化和应用多样化趋势,多种技术和应用交叉渗透至旅游行业的各个方面,预示着全面的智慧旅游时代已经到来。智慧旅游不仅提升了游客的旅游体验,也为旅游管理和服务提供了高效的技术支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值