北京移动官网网站建设,手机端app开发公司,页面自动转跳紧急3秒,派代网#x1f4d1;前言
本文主要是【算法】——蓝桥杯练习题#xff08;二#xff09;的文章#xff0c;如果有什么需要改进的地方还请大佬指出⛺️ #x1f3ac;作者简介#xff1a;大家好#xff0c;我是听风与他#x1f947; ☁️博客首页#xff1a;CSDN主页听风与他 …前言
本文主要是【算法】——蓝桥杯练习题二的文章如果有什么需要改进的地方还请大佬指出⛺️ 作者简介大家好我是听风与他 ☁️博客首页CSDN主页听风与他 每日一句狠狠沉淀顶峰相见 目录 前言1038.含2天数498.回文日期1624.小蓝吃糖果2411.星期几323.用杂志拼接信件文章末尾 1038.含2天数
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 stublong res0;for(int year1900;year9999;year) {if(leapyear(year)) days[2]29;else days[2]28;for(int month1;month12;month) {for(int day1;daydays[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%40n%100!0)||n%4000;}public static boolean contain_2(int n) {while(n0) {if(n%102) {return true;}n/10;}return false;}
}
498.回文日期
package 蓝桥杯第二次;import java.util.Scanner;public class 回文日期 {public static void main(String[] args) {// TODO Auto-generated method stubScanner sc new Scanner(System.in);int n sc.nextInt();int flag10;int flag20;while(true) {n;if(check_day(n)) {if (flag10 check_huiwen(n)) {System.out.println(n);flag11;}if(flag20 check_ab(n)) {System.out.println(n);flag21;}}if(flag11flag21) {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(month12||month1) {return false;}if((year%40year%100!0)||year%4000) {days[2]29;}else {days[2]28;}if(daydays[month]||day1) {return false;}return true;}public static boolean check_huiwen(int num) {int a[] new int[8];int k7;while(num0) {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 k7;while(num0) {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.小蓝吃糖果
package 蓝桥杯第二次;import java.util.Scanner;public class 小蓝吃糖果1 {public static void main(String[] args) {// TODO Auto-generated method stublong sum0;int max0;Scanner sc new Scanner(System.in);int n sc.nextInt();int a[] new int[n];for(int i0;in;i) {a[i] sc.nextInt();if(a[i]max) {max a[i];}suma[i];}if (max (sum1)/2) {System.out.println(Yes);}else {System.out.println(No);}}}
2411.星期几
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 (mn)%70?7:(mn)%7;System.out.println(ans);}
}323.用杂志拼接信件
package 蓝桥杯第二次;import java.util.Scanner;public class 用杂志拼接信件 {public static void main(String[] args) {// TODO Auto-generated method stubScanner sc new Scanner(System.in);String a sc.next();String b sc.next();int num1[] new int[26];int num2[] new int[26];boolean anstrue;for(int i0;ia.length();i) {num1[a.charAt(i)-97];}for(int i0;ib.length();i) {num2[b.charAt(i)-97];}for(int i0;i26;i) {if(num1[i]num2[i]) {ans false;break;}}if (ans) {System.out.println(YES);}else {System.out.println(NO);}}}
文章末尾