HDU6010-Daylight Saving Time

100 篇文章 0 订阅

Daylight Saving Time

                                                                  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                                                                                            Total Submission(s): 130    Accepted Submission(s): 68


Problem Description
Last month, xiaodao together with her friend poteko took a flight from San Francisco to Shanghai.
When they were driving to the airport, xiaodao suddenly realized that the clock time on potekos car is one hour faster than the clock time on her mobile phone. And both of them might be correct, but how can it be? Because that day was Nov 6th, the Daylight saving time switch day this year.
Daylight saving time (DST) or summer time is the practice of advancing clocks during summer months by one hour so that evening daylight lasts an hour longer. It is arguable that using DST can reduce overall energy consumption. Not all of us are using DST now, and for those regions adopting DST, the practices are also different.
In the case of California, effective in the U.S. in 2007 as a result of the Energy Policy Act of 2005, the local time changes from Pacific Standard Time (PST) to Pacific Daylight Time (PDT) at 02:00 to 03:00 on the  second Sunday in March and the local time changes back from PDT to PST at 02:00 to 01:00 on the  first Sunday in November.
Because it is one hour longer on that day, so xiaodao and poteko didn’t miss the flights, but they found it still a little confusing. Interestingly, once xiaodao went back to Shanghai, she met a bug caused by exactly the same issue during the work. You might also be in trouble with DST some day, so here comes this problem and hope it will be helpful.
The local time in California without specifying whether it is PST or PDT could be ambiguous in some cases (e.g. 2016-11-06 01:25:00). In this problem, you are given a local time in California.
Check whether it is “PST”, “PDT”, “Both” or “Neither”.
 

Input
The first line of the input gives the number of test cases, T.
T test cases follow. Each test case consists of one line, a date string written in the following format: YYYY-MM-DD HH:MM:SS.
 

Output
For each test case, first output one line containing “Case #x: ”, where x is the test case number (starting from 1), following a result string which in one of “PST”, “PDT”, “Both” or “Neither”.
 1 ≤ T ≤ 1000.
 date will be legal and between “2007-01-01 00:00:00” and “2100-12-31 23:59:59”.
 

Sample Input
  
  
4 2016-03-13 01:59:59 2016-03-13 02:00:00 2016-11-06 00:59:59 2016-11-06 01:00:00
 

Sample Output
  
  
Case #1: PST Case #2: Neither Case #3: PDT Case #4: Both
 

Source
 

题意:判断时间是PST、PDT,两者都是Both还是两者都不是Neither


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define LL long long
const int INF = 0x3f3f3f3f;

int p[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int r[13] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 };

bool isr(int y)
{
	if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
		return 1;
	return 0;
}

int f(int y, int m, int d)
{
	int ans = 0;
	for (int i = 2007; i < y; i++)
	{
		ans += 365;
		if (isr(i)) ans++;
	}
	for (int i = 1; i < m; i++)
	{
		if (isr(y)) ans += r[i];
		else ans += p[i];
	}
	ans += d;
	return ans;
}

int main()
{
	int y, m, d, hh, mm, ss;
	int t, cas = 0;
	scanf("%d", &t);
	while (t--)
	{
		printf("Case #%d: ", ++cas);
		scanf("%d-%d-%d %d:%d:%d", &y, &m, &d, &hh, &mm, &ss);
		if (m < 3) { printf("PST\n"); continue; }
		else if (m > 3 && m < 11) { printf("PDT\n"); continue; }
		else if (m > 11) { printf("PST\n"); continue; }
		if (m == 3)
		{
			int cnt = 0;
			for (int i = 1; i <= d; i++)
				if (f(y, m, i) % 7 == 0) cnt++;
			if (cnt < 2) { printf("PST\n"); continue; }
			else if (cnt > 2) { printf("PDT\n"); continue; }
			else
			{
				if (f(y, m, d) % 7) { printf("PDT\n"); continue; }
				if (hh == 2) { printf("Neither\n"); continue; }
				if (hh < 2) { printf("PST\n"); continue; }
				if (hh > 2) { printf("PDT\n"); continue; }
			}
		}
		else if (m == 11)
		{
			int cnt = 0;
			for (int i = 1; i <= d; i++)
				if (f(y, m, i) % 7 == 0) cnt++;
			if (cnt < 1) { printf("PDT\n"); continue; }
			else if (cnt > 1) { printf("PST\n"); continue; }
			else
			{
				if (f(y, m, d) % 7) { printf("PST\n"); continue; }
				if (hh == 1) { printf("Both\n"); continue; }
				if (hh < 1) { printf("PDT\n"); continue; }
				if (hh > 1) { printf("PST\n"); continue; }
			}
		}
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值