# 目录

• 1.0的个数
• 2.超级质数
• 3.卡牌

## 1.0的个数

``````import java.util.Scanner;

public class 零的个数 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long num = sc.nextLong();
int ans = 0;
while(num != 0){
long m = num % 10;
if (m == 0)ans++;
else break;
num /= 10;
}
System.out.println(ans);
}
}
``````

## 2.超级质数

``````package lanqiaobei.exe.day12;

public class 超级质数 {
public static void main(String[] args) {
for(int i = 100000000;; i--){
if(check(i)){
System.out.println(i);
break;
}
}
}

static boolean check(int num){
String s = num + "";
for(int i = 0; i < s.length();i ++){
for (int j = i; j < s.length(); j ++){
int tmp = Integer.parseInt(s.substring(i,j+1));
if (!isPrime(tmp))return false;
}
}
return true;
}

//判断是否是质数
static boolean isPrime(int num){
if(num == 1)return false;
for(int i = 2; i <= num / i; i ++){
if(num % i == 0)return false;
}
return true;

}
}
``````

## 3.卡牌

``````import java.io.*;
import java.util.*;

public class 卡牌 {
static PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
static long n,m;
static int N = 200010;
static long[] a = new long[N];
static long[] b = new long[N];

public static void main(String[] args) throws IOException {
n = Long.parseLong(s[0]);
m = Long.parseLong(s[1]);
//可能凑出的最大牌
int target = Integer.MAX_VALUE;
for (int i =0; i < n; i ++){
a[i] = Long.parseLong(s[i]);
}
for (int i =0; i < n; i ++){
b[i] = Long.parseLong(s[i]);
target =(int)Math.min(a[i] + b[i],target);
}

int l = 1,r = target;
while(l < r){
int mid = l + r  + 1>> 1;
if(check(l,r,mid))l = mid;
else r  = mid - 1;
}
pr.println(r);
pr.flush();
}

static boolean check(int l,int r,int mid){
long sum = 0;
for(int i = 0;i < n;  i++){
long v = mid - a[i];
if(v > 0){
sum += v;
if(sum > m)return false;
continue;
} else if(v > b[i]) return false;
}
return true;
}
}
``````
...全文
10 回复 打赏 收藏 举报

3.1w+

2023-03-15 16:38

刷题！