当前位置: 首页 > news >正文

P8651 [蓝桥杯 2017 省 B] 日期问题--注意日期问题中2月的天数 / if是否应该连用

P8651 [P8651 [蓝桥杯 2017 省 B] 日期问题--注意日期问题中2月的天数 / if是否应该连用

      • 题目
  • 分析
      • 代码

题目

在这里插入图片描述

分析

代码中巧妙的用到3重循环,完美的解决了输出的顺序问题【题目要求从小到大】

需要注意的是2月的值,在不同的年份中应该更新2月的值

还有就是最后的3个if【T^T,我一开始写的3个if语句】,要么改成else if,要么把判定的条件改成用“||”连接【害我看半天T^T】,不然用3个if回导致重复输出

代码

#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <climits>  // 包含INT_MAX常量
#include <cctype>
using namespace std;

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

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

int main() {
	int a, b, c;
	scanf("%d/%d/%d", &a, &b, &c);
	//循环从早到晚,巧妙满足了题目要求的从早到晚排列
	for (int year = 1960; year <= 2059; year++) {
		if (check(year))
			month[2] = 29;
		else
			month[2] = 28;
		for (int mth = 1; mth <= 12; mth++) {
			for (int day = 1; day <= month[mth]; day++) {
				if (a == year % 100 && b == mth && day == c)
					printf("%d-%02d-%02d\n", year, mth, day);
				else if (a == mth && b == day && c == year % 100 )
					printf("%d-%02d-%02d\n", year, mth, day);
				else if (a == day && b == mth &&  c == year % 100 )
					printf("%d-%02d-%02d\n", year, mth, day);
			}
		}
	}
	return 0;
}


相关文章:

  • 大模型工程师学习日记(五):基于LangServe的AI服务架构深度解析
  • 汽车电子电控软件开发中因复杂度提升导致的架构恶化问题
  • 《Python基础教程》第16章笔记:测试基础
  • 企业如何将ERP和BPM项目结合提升核心竞争力
  • HarmonyOS学习第12天:解锁表格布局的奥秘
  • 在 Ansys Maxwell 中分析磁场
  • Vue2学习
  • 【Linux】从入门到精通:Make与Makefile完全指南
  • 链表OJ(十)143. 重排链表 中等 公式化哈希解法 中点+逆序+合并
  • 科普|无人机专业术语
  • 训练营总结篇
  • 【数据结构初阶】---时间复杂度和空间复杂度了解及几道相关OJ题
  • 23种设计模式一览【设计模式】
  • VUE element-plus 回车会导致整个页面刷新的问题
  • JMeter 不同协议测试最佳实践汇总
  • 记录一次MQTT慢订阅优化
  • 从矩阵乘法探秘Transformer
  • 基于Python Django的人脸识别上课考勤系统(附源码,部署)
  • Git基本命令索引
  • LeetCode 0132.分割回文串 II:动态规划
  • 动态网站建设包括哪些/产品推销方案
  • 黑河网站seo/怎样把广告放到百度
  • 做网站百度云/网上培训
  • 3d云打印网站开发/商业软文怎么写
  • 建设银行网站解除绑定/长沙seo代理
  • 宣传网站制作方案/怎么做自媒体