首页 > 百度笔试第一题。
头像
java的神秘男友script
编辑于 2020-09-14 21:16
+ 关注

百度笔试第一题。

百度第一题,为啥是0 输出格式是什么?
package NK;
import java.util.Arrays;
import java.util.Scanner;

public class Baidu_01 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int t = in.nextInt();
            for (int x = 0; x < t; x++) {
                int n = in.nextInt();
                int m = in.nextInt();
                int arr[] = new int[n];
                String result ="";
                int brr[] = new int[m];
                for (int i = 0; i < n; i++) {
                    arr[i] = in.nextInt();
                }
                for (int i = 0; i < m; i++) {
                    brr[i] = in.nextInt();
                }
                Arrays.sort(arr);
                Arrays.sort(brr);
                int index = 0;
                for (int i = 0; i < n; i++) {
                    int count = 0;
                    for (int j = index; j < m; j++) {
                        if (brr[j] >= arr[i]) {
                            count= m-j;
                            index = j;
                            break;
                        }
                    }
                    if(i == n-1) {
                        result += count;
                    }else {
                        result += count+" ";
                    }
                }
                System.out.print(result);
            }

        }
    }
}

全部评论

(21) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

热门推荐