LanQiaoTestCodes/寻找三个数的最大乘积2.java

24 lines
546 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package LanQiaoOJ;
import java.util.Arrays;
import java.util.Scanner;
public class 寻找三个数的最大乘积2 {
static int N=1010;
static int []a=new int [N];
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
//如果都是整数——贪心算法——选出最大三个
Arrays.sort(a,0,n);//数组排序算法————时间复杂度nlogn
int ans=a[n-1]*a[n-2]*a[n-3];
ans=Math.max(ans, a[0]*a[1]*a[n-1]);
System.out.print(ans);
}
}
}