【蓝桥杯备战】 Day02

🏠:博客首页: 进击的波吉
📕:今日分享的文章: 【蓝桥杯备战】 Day02
💝:坚持刷蓝桥杯备赛题,分享每日打卡🎈
🌱:Boji 还在努力准备蓝桥杯 ,如有疑问、疏漏之处,请多多指点🙏
☀️:自学成长的路上,感谢大家相伴!No hurry , No Pause !💝

排它平方数

在这里插入图片描述

import java.util.* ;

public class Main {
    public static void main(String[] args) {
        int i = 203880;
        //利用大循环
        r: for (; i<= 987654; i++) {
            String stri = i+"" ;//转换为 字符串
            char[] ch = stri.toCharArray() ;
            
            Arrays.sort(ch) ; 
            //先判断 6位整数是否有相同字符
            for (int j = 0; j < ch.length-1; j++ ) {
                if (ch[j] == ch[j+1] )
                    continue r ; 
            }
            //再判断 结果x中 是否有 6位整数的字符
            long x = (long)i*i ; 
            String str = x+"" ;
            int cnt = 0; 
            for (int j = 0; j< 6;j++) {
                if (str.contains(String.valueOf(ch[j]))) {
                    continue r ; 
                }
                cnt++ ;
                if (cnt == 6) {
                    System.out.println(i) ; 
                }
             }
        }
        
        
    }
}

买不到的数目

在这里插入图片描述

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() ; 
        int m = sc.nextInt() ; 
        System.out.println( n * m - n  -m ) ;
        sc.close();
    }
}

回文日期

在这里插入图片描述

import java.util.* ;

public class Main {
    static int[] days = {0, 31,28, 31,30,31,30,31,31,30,31,30,31} ;
    
    public static boolean check(int date) {
        int year = date / 10000 ;
        int month = date/ 100 % 100 ; 
        int day = date % 100 ; 
        
        if (day == 0 || month <0 || month >12) return false ;
        if (month!= 2 && day > days[month]) return false ; 
        if (month == 2) {
            if ((year %4 == 0 && year %100 !=0) || (year % 400 == 0)) {
                if (day > 29) return false  ;
            }else {
                if (day >28 )return false ; 
            }
        }
        
        return true ;
    }
    
    public static boolean check1(String s1) {
        int len = s1.length() ; 
        char[] ch = s1.toCharArray() ;
        for (int i = 0, j = len -1; i <j; i++, j--) {
            if (ch[i] != ch[j]) return false ; 
        }
        return true ;
    }
    
    public static boolean check2(String s1) {
        //int len = s1.length() ; 
        char[] ch = s1.toCharArray() ; 
        if (check1(s1)) {
            if (ch[0] != ch[2] || ch[1] != ch[3] || ch[0] == ch[1]) { 
                return false ; 
            } 
            return true ; 
        }
        return false ; 
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in) ; 
        int a = sc.nextInt() ;
        int flag = 0; 
        for (int i = a+1 ;; i++) {
            if (check(i)) {
                
                String s = i+"" ; 
                if (check1(s) && flag == 0) {
                    System.out.println(s) ;
                    flag = 1 ; 
                } 
                
                if (check2(s) ) {
                    System.out.println(s) ; 
                    return  ; 
                }
            }
        }
    }
}

约瑟夫环

在这里插入图片描述

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(),k = scan.nextInt();
        scan.close();
        int output = 0;
        for(int i = 2;i<n+1;++i) output = (output+k)%i;
        System.out.print(output+1);
    }
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的波吉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值