2019携程校园招聘编程题(2)取满足条件订单号

 /**
     * 6 找出满足给定范围的订单号
     * 输入:
     * 订单数N
     * 给定入店时间
     * 订单号1 入店时间1 离店时间1
     * 订单号2 入店时间2 离店时间2
     * 订单号3 入店时间3 离店时间3
     * ...
     * 订单号N 入店时间N 离店时间N
     *
     * 输出:
     * 升序排列的满足条件的订单号
     */
    private static void findTimeScope() {
        Scanner in = new Scanner(System.in);
        //订单总数
        int recordNum = in.nextInt();
        //比较时间范围
        int timeScope = in.nextInt();

        //订单号数组
        int[] recordId = new int[recordNum];
        //入店时间数组
        int[] inTime = new int[recordNum];
        //离店时间数组
        int[] outTime = new int[recordNum];

        for (int i = 0; i < recordNum; ) {
            if (in.hasNextInt()) {
                recordId[i] = in.nextInt();
                inTime[i] = in.nextInt();
                outTime[i] = in.nextInt();
                i++;
            }
        }

        //满足条件的订单号
        List<Integer> resultIdList = new ArrayList<>();
        for (int j = 0; j < recordNum; j++) {
            if (timeScope >= inTime[j] && timeScope <= outTime[j]) {
                resultIdList.add(recordId[j]);
            }
        }

        Collections.sort(resultIdList);
        printList(resultIdList);
        in.close();
    }

    private static void printList(List list) {
        for (Object o : list) {
            System.out.println(o);
        }
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值