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

蓝桥杯每日一题2023.11.8

题目描述

题目分析

对于输入的abc我们可以以a为年也可以以c为年,将abc,cab,cba这三种情况进行判断合法性即可,注意需要排序去重,所以考虑使用set

此处为纯模拟的写法,但使用循环代码会更加简洁。

方法一:

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
set<string> st;
string s[N];
int cnt;
int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool is_ren(int x)
{if((x % 4 == 0 && x % 100 != 0)||(x % 400 == 0))return true;return false;
}
int main()
{int a, b, c;scanf("%d/%d/%d",&a, &b, &c);//以a为年 //abcif(a <= 59){//abcif(b <= 12 && b > 0){int x = 2000 + a;if(is_ren(x))m[2] = 29;else m[2] = 28;if(c <= m[b] && c > 0){cnt ++;s[cnt] = "20";if(a < 10)s[cnt] += "0";s[cnt] += (to_string(a) + "-" );if(b < 10)s[cnt] += "0";s[cnt] += (to_string (b) + "-");if(c < 10)s[cnt] +="0";s[cnt] += to_string(c);st.insert(s[cnt]);}}}else if(a > 59){//abcif(b <= 12 && b > 0){int x = 1900 + a;if(is_ren(x))m[2] = 29;else m[2] = 28;if(c <= m[b] && c > 0){cnt ++;s[cnt] = "19";if(a < 10)s[cnt] += "0";s[cnt] += to_string(a) + "-" ;if(b < 10)s[cnt] += "0";s[cnt] += to_string (b) + "-";if(c < 10)s[cnt] +="0";s[cnt] += to_string(c);st.insert(s[cnt]);}}}//以c为年 //cab, cba if(c <= 59){//cabif(a <= 12 && a > 0){int x = 2000 + c;if(is_ren(x))m[2] = 29;else m[2] = 28;if(b <= m[a] && b > 0){s[++ cnt] = "20";if(c < 10)s[cnt] += "0";s[cnt] += to_string(c) + "-" ;if(a < 10)s[cnt] += "0";s[cnt] += to_string (a) + "-";if(b < 10)s[cnt] +="0";s[cnt] += to_string(b);st.insert(s[cnt]);}}//cbaif(b <= 12 && b > 0){int x = 2000 + c;if(is_ren(x))m[2] = 29;else m[2] = 28;if(a <= m[b] && a > 0){cnt ++;s[cnt] = "20";if(c < 10)s[cnt] += "0";s[cnt] += to_string(c) + "-" ;if(b < 10)s[cnt] += "0";s[cnt] += to_string (b) + "-"; if(a < 10)s[cnt] +="0";s[cnt] += to_string(a);st.insert(s[cnt]);}	}}else if(c > 59){//cabif(a <= 12 && a > 0){int x = 1900 + c;if(is_ren(x))m[2] = 29;else m[2] = 28;if(b <= m[a] && b > 0){cnt ++;s[cnt] = "19";if(c < 10)s[cnt] += "0";s[cnt] += to_string(c) + "-" ;if(a < 10)s[cnt] += "0";s[cnt] += to_string (a) + "-";if(b < 10)s[cnt] +="0";s[cnt] += to_string(b);st.insert(s[cnt]);}}//cbaif(b <= 12 && b > 0){int x = 1900 + c;if(is_ren(x))m[2] = 29;else m[2] = 28;if(a <= m[b] && a > 0){cnt ++;s[cnt] = "20";if(c < 10)s[cnt] += "0";s[cnt] += to_string(c) + "-" ;if(b < 10)s[cnt] += "0";s[cnt] += to_string (b) + "-";if(a < 10)s[cnt] +="0";s[cnt] += to_string(a);st.insert(s[cnt]);}}}for(auto i : st){cout << i << '\n';}return 0;
}

方法二:

#include<bits/stdc++.h>
using namespace std;
int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check_valid(int year, int month, int day)
{if(month == 0 || month > 12)return false;if(day == 0)return false;if(month != 2){if(day > days[month])return false;}else{int leap = year % 100 && year % 4 == 0 || year % 400 == 0;if(day > 28 + leap)return false;}return true;
}
int main()
{int a, b, c;scanf("%d/%d/%d", &a, &b, &c);for(int date = 19600101; date <= 20591231; date ++){int year = date / 10000, month = date % 10000 / 100, day = date % 100;if(check_valid(year, month, day)){if(year % 100 == a && month == b && day == c ||month == a && day == b && year % 100 == c ||day == a && month == b && year % 100 == c)printf("%d-%02d-%02d\n", year, month, day);}}return 0;
}
http://www.lryc.cn/news/226255.html

相关文章:

  • 高级PHP应用程序漏洞审核技术【一】
  • 适用于4D毫米波雷达的目标矩形框聚类
  • [模版总结] - 树的基本算法1 - 遍历
  • macOS Sonoma 14.2beta2(23C5041e)发布(附黑白苹果镜像地址)
  • Docker进阶——再次认识docker的概念 Docker的结构 Docker镜像结构 镜像的构建方式
  • postgis函数学习
  • 【Gradle-12】分析so文件和依赖的关系
  • vue项目pdf文件的预览
  • 企业计算机中了mkp勒索病毒怎么办,服务器中了勒索病毒如何处理
  • Android拖放startDragAndDrop拖拽Glide加载堆叠圆角图,Kotlin(5)
  • 1994-2021年分行业二氧化碳排放量数据
  • 如何进行Go程序的打包发布
  • python工具HIKVISION视频编码设备接入网关任意文件下载
  • [NLP] 使用Llama.cpp和LangChain在CPU上使用大模型
  • 开发知识点-Ant-Design-Vue
  • 2022最新版-李宏毅机器学习深度学习课程-P50 BERT的预训练和微调
  • Android codec2 视频框架 之输入buffer
  • Python实现局部二进制算法(LBP)
  • 如何评价现在的CSGO游戏搬砖市场
  • ResourceQuota对象在K8s上的说明
  • 悟空crm二次开发 增加客户保护功能 (很久没有消息,但是有觉得有机会的客户)就进入了保护转态
  • k8s之配置资源管理
  • 赛氪助力全国大学生数学竞赛山东赛区圆满举办
  • pytorch基础语法问题
  • 【面试经典150 | 】颠倒二进制位
  • 十分钟了解自动化测试
  • Redis配置文件
  • [量化投资-学习笔记009]Python+TDengine从零开始搭建量化分析平台-KDJ
  • Activiti6工作流引擎:Form表单
  • Fortran 中的指针