牛客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 );
}
}