count apples and oranges

    /**
     * count apples and oranges whether land on the inclusive [s,t]
     * a is apple tree's cordination, b is orange tree's corditation
     * apples is apple tree's relative cordination ,left relative apple tree is represention by negative value
     * right relative is represention by positive value
     * oranges is same as apples
     * constrant condition :
     * 1<=s,t,a,b,m,n<=10to5 m is apples' size, n is oranges' size
     * -10to5<=d<=10to5 d is apples' cordation plus a's cordation and generate out donation distance and compute oranges' d as well
     * a<s<t<b
     * @param s
     * @param t
     * @param a
     * @param b
     * @param apples
     * @param oranges
     */
    public static void countApplesAndOranges(int s, int t,int a,int b,List<Integer> apples,List<Integer> oranges){
        int val=1;
        for (int i = 0; i < 5; i++) {
            val*=10;
        }
        if (s<1 || s>val){
            return;
        }
        if (a<1 || a>val){
            return;
        }
        if (b<1 || a>val){
            return;
        }
        if (apples.size()<1 || apples.size()>val){
            return;
        }
        if (oranges.size()<1 || apples.size()>val){
            return;
        }
        ArrayList<Integer> appleDonationList = new ArrayList<>();
        apples.forEach(e->{
            int i = a + e;
            appleDonationList.add(i);
        });
        ArrayList<Integer> orangeDonationList = new ArrayList<>();
        oranges.forEach(e->{
            int i = b + e;
            orangeDonationList.add(i);
        });
        int negativeVal = -val;
        ArrayList<Integer> donationList = new ArrayList<>();
        donationList.addAll(appleDonationList);
        donationList.addAll(orangeDonationList);
        for (Integer i : donationList) {
            if (i<negativeVal || i>val){
                return;
            }
        }
        if (a>=s){
            return;
        }
        if (a>=t){
            return;
        }
        if (a>=b){
            return;
        }
        if (s<=a){
            return;
        }
        if (s>=t){
            return;
        }
        if (s>=b){
            return;
        }
        if (t<=a){
            return;
        }
        if (t<=s){
            return;
        }
        if (t>=b){
            return;
        }
        if (b<=a){
            return;
        }
        if (b<=s){
            return;
        }
        if (b<=t){
            return;
        }
        int appleCount=0;
        for (Integer i : appleDonationList) {
            if (i>=s && i<=t){
                appleCount++;
            }
        }
        System.out.println(appleCount);
        int orangeCount=0;
        for (Integer i : orangeDonationList) {
            if (i>=s && i<=t){
                orangeCount++;
            }
        }
        System.out.println(orangeCount);
        return;
    }

#笔试##金融银行面经##牛客创作赏金赛##技术岗笔试题求解#
Java技术 文章被收录于专栏

JavaEE技术 编程开发经验 企业通用技术

全部评论
这段代码看起来是Java语言编写的,它是一个计算苹果和橙子落在指定区间内数量的方法。代码中包含了一些输入验证和计算逻辑,最终输出落在区间 [s, t] 内的苹果和橙子的数量。 如果你有任何关于这段代码的问题或者需要帮助理解某个部分,我都很乐意为你提供帮助哦!或者如果你想要讨论关于求职或者编程的其他话题,也可以告诉我,我们一起聊聊吧!😊 顺便问一下,你有没有什么有趣的问题想要私下跟我讨论的呢?点击我的头像,我们可以开始私信聊天哦!👆🎉
点赞 回复 分享
发布于 03-16 07:40 AI生成

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务