第十四届蓝桥杯填空题(日期统计)

问题描述

小蓝现在有一个长度为 100 的数组,数组中的每个元素的值都在 0 到 9 的范围之内。数组中的元素从左至右如下所示:

复制代码
5 6 8 6 9 1 6 1 2 4 9 1 9 8 2 3 6 4 7 7 5 9 5 0 3 8 7 5 8 1 5 8 6 1 8 3 0 3 7 9 2 7 0 5 8 8 5 7 0 9 9 1 9 4 4 6 8 6 3 3 8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4 0 1 0 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3

现在他想要从这个数组中寻找一些满足以下条件的子序列:

1.子序列的长度为 8

2.这个子序列可以按照下标顺序组成一个 yyyymmdd 格式的日期,并且要求这个日期是 2023 年中的某一天的日期,例如 20230902, 20231223。 yyyy 表示年份, mm 表示月份,dd 表示天数,当月份或者天数的长度只有一位时需要一个前导零补充。

请你帮小蓝计算下按上述条件一共能找到多少个不同的 2023 年的日期。对于相同的日期你只需要统计一次即可。

答案提交

这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

//从第一个2开始就行,所以长度为92

java 复制代码
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int[] a=new int[92];
        for(int i=0;i<92;i++){
          a[i]=scan.nextInt();
        }
        HashSet<Integer> set=new HashSet<>();
        for(int a1=0;a1<=84;a1++) {
        	for(int a2=a1+1;a2<=85;a2++) {
        		for(int a3=a2+1;a3<=86;a3++) {
        			for(int a4=a3+1;a4<=87;a4++) {
        				int year=a[a1]*1000+a[a2]*100+a[a3]*10+a[a4];
        				if(year==2023) {
        					for(int a5=a4+1;a5<=88;a5++) {
        						for(int a6=a5+1;a6<=89;a6++) {
        							int month=a[a5]*10+a[a6];
									if(month>=1&&month<=12) {
										for(int a7=a6+1;a7<=90;a7++) {
        									for(int a8=a7+1;a8<=91;a8++) {
        										int day=a[a7]*10+a[a8];
        											if(day>=1&&day<=31) {
        												if(check(year,month,day)) {
        														int num=(year*100+month)*100+day;
        															set.add(num);
        													}
        											}
        									}
        								}
									}
        						}
        					}
        				}
        			}
        		}
        	}
        }
        System.out.println(set.size());
        scan.close();
    }
    public static boolean check(int year,int month,int day){
      if(month==2&&day<=28){
        return true;
      }
      if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){
        if(day>=1&&day<=31){
          return true;
        }
        else{
          return false;
        }
      }
      if(month==4||month==6||month==9||month==11){
        if(day>=1&&day<=30){
          return true;
        }
        else{
          return false;
        }
      }
      return false;
    }
}
相关推荐
XH华7 小时前
备战蓝桥杯,第九章:结构体和类
学习·蓝桥杯
园小异7 小时前
2026年技术面试完全指南:从算法到系统设计的实战突破
算法·面试·职场和发展
Epiphany.55610 小时前
蓝桥杯备赛题目-----爆破
算法·职场和发展·蓝桥杯
YuTaoShao10 小时前
【LeetCode 每日一题】1653. 使字符串平衡的最少删除次数——(解法三)DP 空间优化
算法·leetcode·职场和发展
Ll130452529815 小时前
Leetcode二叉树part4
算法·leetcode·职场和发展
夏鹏今天学习了吗16 小时前
【LeetCode热题100(99/100)】柱状图中最大的矩形
算法·leetcode·职场和发展
_OP_CHEN18 小时前
【算法基础篇】(五十八)线性代数之高斯消元法从原理到实战:手撕模板 + 洛谷真题全解
线性代数·算法·蓝桥杯·c/c++·线性方程组·acm/icpc·高斯消元法
仰泳的熊猫18 小时前
题目1453:蓝桥杯历届试题-翻硬币
数据结构·c++·算法·蓝桥杯
零售ERP菜鸟1 天前
范式革命:从“信息化”到“数字化”的本质跃迁
大数据·人工智能·职场和发展·创业创新·学习方法·业界资讯
网络安全-杰克1 天前
2026面试自动化测试面试题【含答案】
自动化测试·软件测试·面试·职场和发展