蓝桥杯练习题(二)

📑前言

本文主要是【算法】------蓝桥杯练习题(二)的文章,如果有什么需要改进的地方还请大佬指出⛺️

🎬作者简介:大家好,我是听风与他🥇

☁️博客首页:CSDN主页听风与他

🌄每日一句:狠狠沉淀,顶峰相见

目录

1038.含2天数

java 复制代码
package 蓝桥杯第二次;

public class 含2天数1 {
	
	static int days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long res=0;
		for(int year=1900;year<=9999;year++) {
			if(leapyear(year)) days[2]=29;
			else days[2]=28;
			for(int month=1;month<=12;month++) {
				for(int day=1;day<=days[month];day++) {
					if(contain_2(year)||contain_2(month)||contain_2(day)) {
						res++;
					}
				}
			}
		}
		System.out.println(res);
	}
	
	public static boolean leapyear(int n) {
		return (n%4==0&&n%100!=0)||n%400==0;
	}

	public static boolean contain_2(int n) {
		while(n>0) {
			if(n%10==2) {
				return true;
			}
			n/=10;
		}
		return false;
	}
}

498.回文日期

java 复制代码
package 蓝桥杯第二次;

import java.util.Scanner;

public class 回文日期 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int flag1=0;
		int flag2=0;
		while(true) {
			n++;
			if(check_day(n)) {
				if (flag1==0 && check_huiwen(n)) {
					System.out.println(n);
					flag1=1;
				}
				if(flag2==0 && check_ab(n)) {
					System.out.println(n);
					flag2=1;
				}
			}
			if(flag1==1&&flag2==1) {
				return;
			}
		}
	}
	
	static int days[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
	
	public static boolean check_day(int num) {
		int year = num/10000;
		int month = num%10000/100;
		int day = num%100;
		if(month>12||month<1) {
			return false;
		}
		if((year%4==0&&year%100!=0)||year%400==0) {
			days[2]=29;
		}else {
			days[2]=28;
		}
		if(day>days[month]||day<1) {
			return false;
		}
		return true;
	}
	public static boolean check_huiwen(int num) {
		int a[] = new int[8];
		int k=7;
		while(num>0) {
			a[k--]=num%10;
			num/=10;
		}
		if(a[0]==a[7]&&a[1]==a[6]&&a[2]==a[5]&&a[3]==a[4]) {
			return true;
		}
		return false;
	}
	
	public static boolean check_ab(int num) {
		int a[] = new int[8];
		int k=7;
		while(num>0) {
			a[k--]=num%10;
			num/=10;
		}
		if(a[0]==a[2]&&a[0]==a[5]&&a[0]==a[7]&&a[1]==a[3]&&a[1]==a[4]&&a[1]==a[6]) {
			return true;
		}
		return false;
	}

}

1624.小蓝吃糖果

java 复制代码
package 蓝桥杯第二次;

import java.util.Scanner;

public class 小蓝吃糖果1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long sum=0;
		int max=0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			if(a[i]>max) {
				max = a[i];
			}
			sum+=a[i];
		}
		if (max <= (sum+1)/2) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

2411.星期几

java 复制代码
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int ans = (m+n)%7==0?7:(m+n)%7;
		System.out.println(ans);
    }
}

323.用杂志拼接信件

java 复制代码
package 蓝桥杯第二次;

import java.util.Scanner;

public class 用杂志拼接信件 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int num1[] = new int[26];
		int num2[] = new int[26];
		boolean ans=true;
		for(int i=0;i<a.length();i++) {
			num1[a.charAt(i)-97]++;
		}
		for(int i=0;i<b.length();i++) {
			num2[b.charAt(i)-97]++;
		}
		for(int i=0;i<26;i++) {
			if(num1[i]<num2[i]) {
				ans = false;
				break;
			}
		}
		if (ans) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}

📑文章末尾

相关推荐
-dzk-10 小时前
【堆】LC 347.前 K 个高频元素
算法·堆
H.莓飛10 小时前
【数据结构】栈_OJ题
linux·数据结构·算法·centos
Zootopia62611 小时前
多架 eVTOL集群排班调度方案思考
人工智能·算法·数学建模·matlab·动态规划·无人机·evtol
ZealSinger11 小时前
Spring7 RestTemplate弃用迁移
java·spring·后端开发·restclient
和裕11 小时前
年度框架直供 vs 零散按需采购:定制纸箱采购成本、交付与服务核心区别全对比
大数据·运维·网络·人工智能·算法
朝朝辞暮i11 小时前
C++ 第 13 课:值传递 —— 为什么函数里改了,外面却没变?
java·c++·算法
弹简特11 小时前
【Java项目-企悦抽】16-抽奖模块01-获取活动完整信息接口实现
java·开发语言·状态模式·springboot
淡海水11 小时前
02-02-原理篇-分代GC
算法·unity·c#·游戏引擎·.net·gc
泡茶喝茶写代码12 小时前
A股量化数据工程:从 REST 接口到策略信号(第 1 篇):指数列表与实时行情接入
java·python·股票数据api·股票数据·股票数据api接口·股票api数据接口·股票量化数据接口
Sarvartha12 小时前
接口基础知识
java·开发语言