zoukankan      html  css  js  c++  java
  • 牛客2018校招 1. 拼多多 最大乘积

    第一题:主要看一下输入输出.

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Comparator;
    
    public class Main{
        public static void main(String[] args) throws IOException{
            InputStreamReader ir = new InputStreamReader(System.in);
            BufferedReader bf = new BufferedReader(ir);
            int n = Integer.parseInt(bf.readLine());
            String[] str = bf.readLine().split(" ");
            int[] nums = new int[str.length];
            for (int i = 0;i < nums.length; i++)
                nums[i] = Integer.parseInt(str[i]);
            System.out.println(Main.method(nums));
        }
        
        public static long method(int[] arr){
            int max1 = Integer.MIN_VALUE, max2 = Integer.MIN_VALUE, max3 = Integer.MIN_VALUE;
            int min1 = Integer.MAX_VALUE, min2 = Integer.MAX_VALUE;
            for (int n : arr){
                if (n > max1){
                    max3 = max2;
                    max2 = max1;
                    max1 = n;
                }else if(n > max2){
                    max3 = max2;
                    max2 = n;
                }else if(n > max3){
                    max3 = n;
                }
                
                if (n < min1){
                    min2 = min1;
                    min1 = n;
                }else if(n < min2){
                    min2 = n;
                }
            }
            return Math.max( (long)max1*max2*max3, (long)max1*min1*min2 );
        }
    }
    
  • 相关阅读:
    python input函数
    linux可用内存判断
    python if-elif-else 判断
    python if判断
    python使用range()函数创建数字列表list
    python range函数
    python语法缩进
    python for循环
    python列表删除和排序
    hbctf 父亲的信
  • 原文地址:https://www.cnblogs.com/whyaza/p/10669165.html
Copyright © 2011-2022 走看看