🏠:博客首页: 进击的波吉
📕:今日分享的文章:【蓝桥杯备战】 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);
}
}