蓝桥杯 日期计算(模拟+坑多)

10 篇文章 0 订阅
9 篇文章 0 订阅

考虑闰年,考虑年份,月份是否在范围内,考虑去重

acwing传送门

// #pragma GCC optimize(2)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO                       \
	ios::sync_with_stdio(false); \
	// cout.tie(0);
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 2e5 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
struct Node
{
	int y, m, d;
};
bool cmp(Node a, Node b)
{
	if (a.y != b.y)
	{
		return a.y < b.y;
	}
	else
	{
		if (a.m != b.m)
		{
			return a.m < b.m;
		}
		else
			return a.d < b.d;
	}
}
bool check(int a, int b, int c)
{
	bool f = false;
	bool run = false;
	for (int i = 1960; i <= 2059; i++)
	{
		if (i == a)
		{
			f = true;
			break;
		}
	}
	if (f == false || !(b >= 1 && b <= 12))
		return false;
	if ((a % 4 == 0 && a % 100 != 0) || (a % 400 == 0))
		run = true;
	if (run)
	{
		int num = m[b];
		if (b == 2)
			num += 1;
		if (c >= 1 && c <= num)
			return true;
		else
			return false;
	}
	else
	{
		int num = m[b];
		if (c >= 1 && c <= num)
			return true;
		else
			return false;
	}
}

int main()
{
#ifdef WXY
	freopen("in.txt", "r", stdin);
//	 freopen("out.txt", "w", stdout);
#endif
	IO;
	int a, b, c;
	char ch;
	cin >> a >> ch >> b >> ch >> c;
	int x = 1900;
	int y = 2000;
	vector<Node> v;
	if (check(x + a, b, c))
	{
		v.push_back({x + a, b, c});
	}
	if (check(y + a, b, c))
	{
		v.push_back({y + a, b, c});
	}
	int t1 = c, t2 = a, t3 = b;
	if (check(x + t1, t2, t3))
	{
		v.push_back({x + t1, t2, t3});
	}
	if (check(y + t1, t2, t3))
	{
		v.push_back({y + t1, t2, t3});
	}
	t1 = c, t2 = b, t3 = a;
	if (check(x + t1, t2, t3))
	{
		v.push_back({x + t1, t2, t3});
	}
	if (check(y + t1, t2, t3))
	{
		v.push_back({y + t1, t2, t3});
	}
	sort(v.begin(), v.end(), cmp);
	if (v.size() == 0)
		return 0;
	else
	{
		printf("%04d-%02d-%02d\n", v[0].y, v[0].m, v[0].d);
		for (int i = 1; i < v.size(); i++)
		{
			if (v[i].y == v[i - 1].y && v[i].m == v[i - 1].m && v[i].d == v[i - 1].d)
				continue;
			printf("%04d-%02d-%02d\n", v[i].y, v[i].m, v[i].d);
		}
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值